jQuery实现ajax的叠加和停止(终止ajax请求)
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>
相关推荐
TONIYH 2020-07-22
83510998 2020-07-18
wcqwcq 2020-06-26
delmarks 2020-06-14
ppsurcao 2020-06-14
tthappyer 2020-06-07
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03