ajaxSubmit

ajaxSubmit(object)

 

 

 ajaxSubmit() provides a mechanism for submitting an HTML form using AJAX. 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; });

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值