var pendingRequests = [];
var generatePendingRequestKey = function (obj)
{
return obj.data || {};
}
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
// 不重复发送相同请求
var key = generatePendingRequestKey(options);
if (!pendingRequests[key]) {
jqXHR.pendingRequestKey = key;
pendingRequests[key] = "true";
} else {
// or do other
jqXHR.abort();
}
var complete = options.complete;
options.complete = function (jqXHR, textStatus) {
// clear from pending requests
pendingRequests[jqXHR.pendingRequestKey] = null;
if ($.isFunction(complete)) {
complete.apply(this, arguments);
}
};
});
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)