当连续进行多个请求,并且请求的url地址相同时。放弃前面的所有请求,只执行最后一次请求。

// 当连续进行多个请求,并且请求的url地址相同时。放弃前面的所有请求,只执行最后一次请求。
function ajaxFilter(){
var pendingRequests = {};
jQuery.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
var key = options.url;
console.log(key);
if (!pendingRequests[key]) {
pendingRequests[key] = jqXHR;
}else{
//jqXHR.abort(); //放弃后触发的提交
pendingRequests[key].abort(); // 放弃先触发的提交
}
 
var complete = options.complete;
options.complete = function(jqXHR, textStatus) {
pendingRequests[key] = null;
if (jQuery.isFunction(complete)) {
complete.apply(this, arguments);
}
};
});
}
posted @ 2019-04-09 10:30  阿毛蛋蛋  阅读(613)  评论(0编辑  收藏  举报