如何判断 jQuery 是否有挂起的 ajax 请求

2025-04-02 16:23:56
推荐回答(1个)
回答1:

var xhrCount = 0;

// AJAX
var xhr = new XMLHttpRequest();
xhrCount += 1;
...
xhr.onreadystatechange = function () {
...
if (xhr.readyState === 4)
xhrCount -= 1;
};

// Check if all AJAX requests done
if (xhrCount > 0)
console.log('Another AJAX request is processing...');