Home >Web Front-end >JS Tutorial >jQuery uses ajaxSubmit() to submit a form example
This article mainly introducesjQueryUsing ajaxSubmit() to submit a form example, using the extended third-party plug-in jquery.form to implement it. Friends who need it can refer to it
ajaxSubmit(obj) The method is a method in jquery.form.js, a plug-in of jQuery, so you need to introduce this plug-in first to use this method. As shown below:
The code is as follows:
So, how to pass ajaxSubmit(obj ) submit data? First we need a form:
XHTML
The code is as follows:
The above is a form that needs to submit content. Normally, if we submit it directly through the form, the current page will jump after submission. Go to the page pointed to by the form's action. However, many times we do not want the page to jump after submitting the form, then we can use ajaxSubmit(obj) to submit the data. The usage method is as follows:
The code is as follows:
$('button').on('click', function() {
$('form') .on('submit', function() {
var title = $('inpur[name=title]').val(),
content = $('textarea').val();
$ (this) .ajaxSubmit ({
Type: 'Post', // Submission method get/Post
Url: 'your url', // URL
Data: {
'title': title,
'Content': Content
},
SUCCESS: Function (data) {// data Save the data returned after submitted, generally json Data
// Related processing of data can be done here
alert('Submission successful!'); ; // Reset the form after submission
});
return false; // Prevent the form from automatically submitting
Event
;
The above is the detailed content of jQuery uses ajaxSubmit() to submit a form example. For more information, please follow other related articles on the PHP Chinese website!