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 to not clickable. The specific code is as follows:
1 $ ('# submit '). click (function () {2 var objbutton = $ (this); 3 var content = $ ('# content '). val (); 4 $. ajax ({5 URL: web_url + 'jquery. PHP ', 6 type: 'post', 7 cache: false, 8 data: 'Action = submit & content =' + content, 9 beforesend: function () {// execute 10 objbutton when the Ajax request is triggered. val ('Submit '). ATTR ('Disabled ', true); // change the text on the submit button and set the button to 11}, 12 success: function (txt) {// After the Ajax request is successful, execute 13 // here for the relevant logic judgment. According to your own situation, see 14}, 15 Error : Function () {// when an Ajax error occurs, execute 16 alert ('data request error! '); 17}, 18 complete: function () {// execute 19 objbutton when the Ajax request is complete. val ('Submit '). ATTR ('Disabled ', false); // modify the text on the submit button and set the button to 20} 21}); 22 });
How to disable repeated submission through Ajax