jquery submits a form using Ajaxsubmit () (in case you don't want the page to jump)

Source: Internet
Author: User

Original: http://www.jb51.net/article/48728.htm

The Ajaxsubmit (obj) method is a plug-in jquery.form.js inside the jquery method, so using this method requires first introducing this plugin. As shown below:

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

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

<form>Title:<inputtype= "text"name= "title" /><BR/>content:<textareaname= "Content"><textarea/><BR/>    <Button>Submit</Button></form>

The above is a form that needs to submit content, usually, we submit directly through the form, after the submission of the current page to the form of the action point to the page. However, many times we do not want to submit the form after the page jumps, then we can use Ajaxsubmit (obj) to submit the data. Use the following method:

$ (' button '). On (' click ',function() {    $(' form '). On (' Submit ',function() {        vartitle = $ (' inpur[name=title] '). Val (), Content= $ (' textarea '). Val (); $( This). Ajaxsubmit ({type:' Post ',//How to submit Get/postURL: ' Your URL ',//URLs that need to be submitteddata: {' Title ': Title,' Content ': Content}, Success:function(data) {//data that is returned after the commit is saved, typically JSON data                //data can be processed hereAlert (' Submit success! ‘); }            $( This). Resetform ();//Reset form after submission        }); return false;//prevent forms from automatically submitting events    });});

jquery submits a form using Ajaxsubmit () (in case you don't want the page to jump)

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.