JQuery.form.js is a form plugin that supports AJAX form submissions and Ajax file uploads.
Official website: http://plugins.jquery.com/form/
Api
Ajaxform |
Add all the required event listeners to prepare for the AJAX submission form. Ajaxform cannot submit the form. In the ready function of document, use Ajaxform to prepare the form for the AJAX submission. |
accepts 0 or 1 parameters. A parameter can be a callback function, or it can be an options object. |
$ ("#formid"). Ajaxform (); |
Ajaxsubmit |
Submit a form using AJAX. |
accepts 0 or 1 parameters. A parameter can be a callback function, or it can be an options object. |
$ ("#formid"). Ajaxsubmit (); Or $ ("#formid"). Submit (function () { $ (this). Ajaxsubmit (); return false; }); |
Formserialize |
Serializes (or serialize) a form into a query string. This method returns a string in the following format: Name1=value1&name2=value2. |
No |
$ ("#formid"). Formserialize (); |
Fieldserialize |
Serializes (or serialize) the field elements of a form into a single query string. This is handy when only a subset of the form fields need to be serialized (or serializable). Returns a string in the following format: Name=value1&name2=value2. |
No |
$ ("#formid. Specialfields"). Fieldserialize (); |
Fieldvalue |
Returns the value of the form element that matches the inserted array. The method returns data in the form of an array. If the element value is determined to be invalid, the array is empty. |
No |
$ ("#formid:p assword"). Fieldvalue (); |
Resetform |
Restores the form to its original state. |
No |
$ ("#formid"). Resetform (); |
ClearForm |
Clears the form element. This method resets all text, password, textarea, clears the selection in the Select element, and resets all radio and CheckBox buttons to the unselected state. |
No |
$ ("#formid"). ClearForm (); |
Clearfields |
Clears the field element. Only some form elements are easy to use when they need to be cleared. |
No |
$ ("#formid. Specialfields"). Clearfields (); |
Options Object
Both Ajaxform and Ajaxsubmit support a wide range of option parameters, which can be provided using an options object.
Target |
Indicates the element in the page that is updated by the server response. The value of the element may be specified as a jquery selector string, a jquery object, and a DOM element. |
Default value: null |
wr. |
Specifies the URL to submit the form data. |
Default value: The Action property value of the form |
Type |
Specifies the method by which the form data is submitted: "GET" or "POST". |
Default value: GET |
Beforesubmit |
The callback function that was called before the form was submitted. If the callback function returns false, the form will not be committed. The callback function takes three invocation parameters: the form data as an array, the JQuery form object, and the options object in the incoming ajaxform/ajaxsubmit. |
Default value: null |
Success |
callback function that is called after the form has been successfully committed. The datatype option value then determines whether to return ResponseText or responsexml values. |
Default value: null |
DataType |
Data type returned: null, XML, script, json one of them. |
Default value: null |
Resetform |
Indicates whether the form submission succeeds if it is reset. |
Default value: null |
ClearForm |
Indicates whether the form data is purged if the form submission succeeds. |
Default value: null |
Example:
var options={target: ' #output ',//Put the contents of the server back into an element with ID output beforesubmit:showrequest,//Pre-commit callback function Succe Ss:showresponse,//post-commit callback function///Url:url,//default is the action of form, if stated, will overwrite//Type:type,//default value is the method of form ( "Get" or "POST"), if declared, will overwrite//datatype:null,///HTML (default), XML, script, JSON accept server-side returned type//Clearform:true,/// After a successful commit, clear the value of all form elements//resetform:true,//After successful commit, reset the value of all form elements timeout:3000//Limit the request time, when the request is greater than 3 seconds, jump out of the request}function Sho Wrequest (FormData, Jqform, Options) {//FormData: Array object, when the form is submitted, the form plug-in automatically submits the data in an AJAX format such as [{Name:user,value:val},{name :p Wd,value:pwd}]//Jqform:jquery object that encapsulates the form's element//Options:options object var querystring=$.param (formData); name=1&address=2 var formelement=jqform[0]; Convert Jqform to Dom object Var Address=formelement.address.value; Access the DOM element of Jqform return true; As long as it does not return false, the form will be submitted, where the form element can be verified}function showresponse (responsetext,statustext) {//datatype=xml var name=$ ("Name ", ResponsexML). text (); var address=$ ("Address", Responsexml). text (); $ ("#xmlout"). HTML (name+ "" +address); Datatype=json $ ("#jsonout"). HTML (data.name+ "" +data.address);}
JQuery.form.js jQuery Ajax Asynchronous Commit form