jQuery實現ajax的疊加和停止的關鍵代碼如下所示:
<!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>
以上所述是小編給大家介紹的jQuery實現ajax的疊加和停止(終止ajax請求),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家的支持!