Use of the AJAX submission plugin for JavaScript forms

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.