jquery uses Ajaxsubmit () to submit a form example _jquery

Source: Internet
Author: User

The Ajaxsubmit (obj) method is a way of using jquery as a plug-in jquery.form.js, so you need to introduce the plugin first. As shown below:

Copy Code code as follows:

<script src= "Http://code.jquery.com/jquery-1.11.0.min.js" ></script>
<script src= "Http://malsup.github.io/jquery.form.js" ></script>

So how do you submit data through Ajaxsubmit (obj)? First we need a form:

Xhtml

Copy Code code as follows:

<form>
Title: <input type= "text" name= "title"/><br/>
Content: <textarea name= "Content" ><textarea/><br/>
<button> Submit </button>
</form>


The above is a form that needs to be submitted, and normally, we submit it directly through form, and the current page jumps to the page that the form's action points to when it is submitted. However, many times we do not want to submit the form after the page jump, then we can use Ajaxsubmit (obj) to submit the data. The use method looks like this:

Copy Code code as follows:

$ (' button '). On (' click ', function () {

$ (' form '). On (' Submit ', function () {
var title = $ (' inpur[name=title] '). Val (),
Content = $ (' textarea '). Val ();

$ (this). Ajaxsubmit ({
Type: ' Post ',//Submit method Get/post
URL: ' Your URL ',//URL to submit
Data: {
' title ': Title,
' Content ': Content
},
Success:function (data) {//File returns after submission, typically JSON data
Data can be related to processing here
Alert (' Commit success! ');
}
$ (this). Resetform (); Reset form after submission
});
return false; Prevent forms from automatically submitting events
});
});

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.