停止jQuery中的所有活动Ajax请求我有一个问题,当提交表单时,所有活动的Ajax请求都会失败,这会触发错误事件。如何在没有琐碎错误事件的情况下停止jQuery中的所有活动Ajax请求?
3 回答

慕莱坞森
TA贡献1810条经验 获得超4个赞
var request = $.ajax({ type: 'POST', url: 'someurl', success: function(result){}});
request.abort();

波斯汪
TA贡献1811条经验 获得超4个赞
<HEAD>
<script type="text/javascript"> $(function() { $.xhrPool = []; $.xhrPool.abortAll = function() { $(this).each(function(i, jqXHR) { // cycle through list of recorded connection jqXHR.abort(); // aborts connection $.xhrPool.splice(i, 1); // removes from list by index }); } $.ajaxSetup({ beforeSend: function(jqXHR) { $.xhrPool.push(jqXHR); }, // annd connection to list complete: function(jqXHR) { var i = $.xhrPool.indexOf(jqXHR); // get index for current connection completed if (i > -1) $.xhrPool.splice(i, 1); // removes from list by index } }); })</script>
- 3 回答
- 0 关注
- 873 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消