This time I will bring you jQueryWhat methods are there to terminate ajax requests? What are the precautions for jQuery to terminate ajax requests? Here are actual cases, let’s take a look.
The key code for jQuery to implement ajax overlay and stop is as follows:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>jQuery中终止Ajax请求</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="http://common.cnblogs.com/script/jquery.js" type="text/javascript"></script> <script> var arrayAJAX = new Array(); $(function () { $("#btn").bind("click", function () { for (var i = 0; i < 100; i++) { starAJAX(i); } }); $("#bt2").bind("click", function () { stopAJAX(); alert("终止AJAX请求"); }); }) //停止ajax function stopAJAX() { for (var i = 0; i < arrayAJAX.length; i++) { arrayAJAX[i].abort(); } arrayAJAX = new Array(); } //添加ajax function starAJAX(i) { var options = { url: '/Home/addallrecommandbook', data: "html=" + i, success: function (data, textStatus) { if (textStatus == 'success') { alert("添加成功!"); } else { } }, error: function (x, msg, err) { } }; arrayAJAX.push($.ajax(options)); } </script> </head> <body> <input type="button" id="btn" value="starAJAX" /> <input type="button" id="bt2" value="stopAjax" /> </body> </html>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
Detailed explanation of the steps of asp processing json data
htmlDetailed explanation of the method of directly displaying JSON
The above is the detailed content of What methods does jQuery have to terminate ajax requests?. For more information, please follow other related articles on the PHP Chinese website!