JQuery USES the ajaxSubmit of submission form example
- 2020-03-30 02:34:46
- OfStack
The ajaxSubmit(obj) method is a plug-in for jQuery that is used in jQuery. 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:
$('button').on('click', function() {
$('form').on('submit', function() {
var title = $('inpur[name=title]').val(),
content = $('textarea').val();
$(this).ajaxSubmit({
type: 'post', //Get /post
url: 'your url', //Url to be submitted
data: {
'title': title,
'content': content
},
success: function(data) { //Data stores the data returned after submission, typically json data
//Data can be correlated here
alert(' Submission successful! ');
}
$(this).resetForm(); //Reset the form after submission
});
return false; //Prevents the form from automatically submitting events
});
});