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