好库网 好库网首页 | 我的好库
JQuery入门

ajaxSubmit(object)-JQuery API

发布者:jquery2000
发布日期:2011/4/6 15:27:49   更新日期:2011/4/6 15:27:49
阅读次数:7189
评分:4.80
介绍:ajaxSubmit(object) ajaxSubmit()提供一个使用AJAX提交HTML表单的机制。
正文:

ajaxSubmit(object)

ajaxSubmit()提供一个使用AJAX提交HTML表单的机制。

 ajaxSubmit accepts a single argument which can be either a success callback function or an options Object. If a function is provided it will be invoked upon successful completion of the submit and will be passed the response from the server. If an options Object is provided, the following attributes are supported: target: Identifies the element(s) in the page to be updated with the server response. This value may be specified as a jQuery selection string, a jQuery object, or a DOM element. default value: null url: URL to which the form data will be submitted. default value: value of form's 'action' attribute method:

 

返回值

jQuery

 

参数

object (options): literal containing options which control the form submission process 

示例

说明:

Submit form and alert server response

 

jQuery 代码:

$('#myForm').ajaxSubmit(function(data) { alert('Form submit succeeded! Server returned: ' + data); }); 

--------------------------------------------------------------------------------

 

 

说明:

Submit form and update page element with server response

 

jQuery 代码:

var options = { target: '#myTargetDiv' }; $('#myForm').ajaxSubmit(options); 

--------------------------------------------------------------------------------

 

 

说明:

Submit form and alert the server response

 

jQuery 代码:

var options = { success: function(responseText) { alert(responseText); } }; $('#myForm').ajaxSubmit(options); 

--------------------------------------------------------------------------------

 

 

说明:

Pre-submit validation which aborts the submit operation if form data is empty

 

jQuery 代码:

var options = { beforeSubmit: function(formArray, jqForm) { if (formArray.length == 0) { alert('Please enter data.'); return false; } } }; $('#myForm').ajaxSubmit(options); 

--------------------------------------------------------------------------------

 

 

说明:

json data returned and evaluated

 

jQuery 代码:

var options = { url: myJsonUrl.php, dataType: 'json', success: function(data) { // 'data' is an object representing the the evaluated json data } }; $('#myForm').ajaxSubmit(options); 

--------------------------------------------------------------------------------

 

 

说明:

XML data returned from server

 

jQuery 代码:

var options = { url: myXmlUrl.php, dataType: 'xml', success: function(responseXML) { // responseXML is XML document object var data = $('myElement', responseXML).text(); } }; $('#myForm').ajaxSubmit(options); 

--------------------------------------------------------------------------------

 

 

说明:

submit form and reset it if successful

 

jQuery 代码:

var options = { resetForm: true }; $('#myForm').ajaxSubmit(options); 

--------------------------------------------------------------------------------

 

 

说明:

Bind form's submit event to use ajaxSubmit

 

jQuery 代码:

$('#myForm).submit(function() { $(this).ajaxSubmit(); return false; });


评论 [发表评论]
账号 密码 还没帐号呢,现在注册一个?

免责声明:好库网所展示的信息由买卖双方自行提供,其真实性、准确性和合法性由信息发布人负责。好库网不提供任何保证,并不承担任何法律责任。