如何遍历XMLHttpRequest.prototype.send responseTexts?

我正在尝试通过JS检测ajax响应,并且在此SO帖子JavaScript: Detect AJAX requests上找到了以下代码

问题是我收到两个响应,并且触发另一个函数运行2x。

是否可以遍历响应并仅发送第一个响应,而不同时发送两个响应?某种IndexOf 0?

(function () {

var proxied = window.XMLHttpRequest.prototype.send;
window.XMLHttpRequest.prototype.send = function () {
    // console.log( arguments );
    var pointer = this
    var intervalId = window.setInterval(function () {
        if (pointer.readyState != 4) {
            return;
        }
        var data = pointer.responseText;
        var jsonResponse = JSON.parse(data);
        console.log('json response: ',jsonResponse);
        clearInterval(intervalId);
    },1);
    return proxied.apply(this,[].slice.call(arguments));
};

})();
woshiriluobingcheng1 回答:如何遍历XMLHttpRequest.prototype.send responseTexts?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3169243.html

大家都在问