Ajax Submission Plugin
Form.js form: official website: http://malsup.com/jquery/form/
The Form.js plugin has two core methods: Ajaxform () and Ajaxsubmit (), which are assembled from the control form element
To the ability to decide how to manage commits.
// Ajaxform Submission Method $ (' #reg '). Ajaxform (function () {alert (' Submit succeeded! ');});
Using the Ajaxform () method, the Ajax commits are implemented directly. Automatically blocks the default behavior, and it commits the
The default page is the value of the Action property of the form control. The way to commit is the value of the method property.
// Ajaxsubmit () Submission method $ (' #reg '). Submit (function () {$ (this). Ajaxsubmit ( function () {alert (' Commit succeeded! '); }); returnfalse;});
Note: the Ajaxform () method, which is submitted directly against the form, prevents the default behavior. and Ajaxsubmit ()
method, because it is for the submit () method, you need to manually block the default behavior.
Option parameter
The option parameter is an object that is passed as a key-value pair, which can be used to set the functions of various AJAX submissions.
Yes.
$ (' #reg '). Submit (function() {$ ( This). Ajaxsubmit ({URL:' Test.php ',//set the URL of the submission to override the Action propertyTarget: ' #box ',//the contents returned by the server are stored in #box.Type: ' POST ',//Get,postDataType:NULL,//Xml,json,script, default is nullClearForm:true,//after a successful submission, clear the formResetform:true,//after a successful commit, reset the formData: {//add additional data submissionsAAA: ' BBB ', CCC:' DDD '. }, Beforesubmit:function(FormData, Jqform, options) {alert (formdata[0].name);//get the name of the passed form elementalert (Formdata[0].value);//get the value of the pass form elementalert (jqform);//the jquery object that gets the formalert (options);//get the current Options settings PropertiesAlert (' in Submission!!! ‘); return true; }, Success:function(ResponseText, statustext) {alert (ResponseText+ statustext);//Callback after success }, Error:function(Event, ErrorText, ErrorType) {//error when callingAlert (ErrorText +ErrorType); }, }); return false;});
Tool methods
// form Serialization alert ($ (' #reg '). Formserialize ()); // serializes a field alert ($ (' #reg #user '). Fieldserialize ()); // get the value of a field alert ($ (' #reg #user '). Fieldvalue ()); // Reset the form $ (' #reg '). Resetform ()
Use of the AJAX submission plugin for JavaScript forms