This article mainly describes how to prevent repeated submission when using jquery ajax.
In fact, the method is very simple, that is, after the user clicks the submit button, set the button as not clickable. The specific code is as follows:
$ ('# Submit '). click (function () {var objButton = $ (this); var content = $ ('# content '). val (); $. ajax ({url: web_url + 'jquery. php ', type: 'post', cache: false, data: 'Action = submit & content =' + content, beforeSend: function () {// execute the objButton when the ajax request is triggered. val ('Submit '). attr ('Disabled ', true); // change the text on the submit button and set the button to not clickable}, success: function (txt) {// After the ajax request is successful, execute // here for the relevant logic judgment. For details, refer to the following link:}, error: function () {// execute alert when an ajax error occurs ('data request error! ') ;}, Complete: function () {// execute the objButton when the ajax request is complete. val ('Submit '). attr ('Disabled ', false); // modify the text on the submit button and set the button to clickable }});});
For the usage of jquery ajax, refer to this article:
$. Post and $. ajax Usage Analysis in Jquery
Articles you may be interested in
- The jquery setting button cannot be clicked to prevent repeated data submission
- Jquery $. ajax $. post or $. get: How to submit the checkbox Value
- Prohibit web page right-click, copy, save as, View Source file and other functions to implement web page source code protection
- Js determines whether the variable is a number
- Ajax timeout processing in jquery
- Using JavaScript to prohibit browsers from directly copying article content
- Measures to prevent the return of the backspace key
- Js to determine whether an array contains repeated values