jQuery API 返回首页目录 | jQuery API 中英文对照版
ajaxForm(object)

ajaxForm(object)

ajaxForm() provides a mechanism for fully automating form submission. The advantages of using this method instead of ajaxSubmit() are: 1: This method will include coordinates for <input type="image" /> elements (if the element is used to submit the form). 2. This method will include the submit element's name/value data (for the element that was used to submit the form). 3. This method binds the submit() method to the form for you. Note that for accurate x/y coordinates of image submit elements in all browsers you need to also use the "dimensions" plugin (this method will auto-detect its presence). The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely passes the options argument along after properly binding events for submit elements and the form itself. See ajaxSubmit for a full description of the options argument.

返回值

jQuery

参数

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

示例

说明:

Bind form's submit event so that 'myTargetDiv' is updated with the server response when the form is submitted.

jQuery 代码:
var options = { target: '#myTargetDiv' }; $('#myForm').ajaxSForm(options);

说明:

Bind form's submit event so that server response is alerted after the form is submitted.

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

说明:

Bind form's submit event so that pre-submit callback is invoked before the form is submitted.

jQuery 代码:
var options = { beforeSubmit: function(formArray, jqForm) { if (formArray.length == 0) { alert('Please enter data.'); return false; } } }; $('#myForm').ajaxSubmit(options);
相关链接
asp之家 | jQuery官方网站 | jQuery中文网 | 电子书作者网站 | 电子书作者blog