jQuery API | jQuery API 中英文对照版 - jQuery在线查询手册 |
ajaxSubmit(object) |
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 参数
示例说明: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; }); |