jquery Ajax put on the repeat Click event Beforesend method

Source: Internet
Author: User

Prevent duplicate data
In the actual project development, the submission of the form is often due to the network or its reasons, the user click the Submit button mistakenly believe that they did not succeed, and then repeat the button operation times, if the page front-end code does not do some corresponding processing, often lead to many of the same data inserted into the database, resulting in increased dirty data. To avoid this behavior, disable the Commit button in the Beforesend method in the $.ajax request and wait until the AJAX request is complete and the recovery button is available.

As an example:

Submit form data to background processing
$.ajax ({
Type: "Post",
Data:studentinfo,
ContentType: "Application/json",
URL: "/home/submit",
Beforesend:function () {
Disable buttons to prevent duplicate submissions
$ ("#submit"). attr ({disabled: "disabled"});
},
Success:function (data) {
if (data = = "Success") {
Empty the input box
Clearbox ();
}
},
Complete:function () {
$ ("#submit"). Removeattr ("Disabled");
},
Error:function (data) {
Console.info ("Error:" + data.responsetext);
}
});

Simulate toast effects
The AJAX request server loads the data list when prompted loading ("load, please later ..."),

$.ajax ({
Type: "Post",
ContentType: "Application/json",
URL: "/home/getlist",
Beforesend:function () {
$ ("Loading"). Show ();
},
Success:function (data) {
if (data = = "Success") {
// ...
}
},
Complete:function () {
$ ("Loading"). Hide ();
},
Error:function (data) {
Console.info ("Error:" + data.responsetext);
}
});

jquery Ajax put on the repeat Click event Beforesend method

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.