How jquery ajax prevents repeated submissions

Source: Internet
Author: User

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

Related Article

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.