有没有一种简单的方法来检测是否XMLHtt prequest是活跃在浏览器窗口?或者,有多少是活跃的? IE浏览器。有没有一种方法来检测是否有任何的AJAX在浏览器窗口中把活动?
Is there an easy way to detect if an XMLHttpRequest is active in the browser window? Or how many are active? ie. Is there a way to detect if there are any AJAX calls active in my browser window?
扩展的问题:使用JavaScript是有办法,我可以看到,如果任何XMLHtt prequests是开放的?如window.XMLisActive()或类似的东西?
Extension of question: Using javascript is there a way I can see if any XMLHttpRequests are open? Such as "window.XMLisActive()" or something like that?
解决方案:最后写一个包装XMLHtt prequest https://gist.github.com/1820380
Solution: Ended up writing a wrapper for XMLHttpRequest https://gist.github.com/1820380
推荐答案
有没有一种方法来检测从JS打开的连接,除非你写一个包装 XmlHtt prequest
(或猴子补丁吧),其跟踪打开的连接。
There is not a way to detect an open connection from JS unless you write a wrapper for XmlHttpRequest
(or monkey patch it) that keeps track of opened connections.
下面是kidcapital的猴子补丁,不知道它是完美的,但它是一个良好的开端
Here's kidcapital's monkey patch, not sure if it's perfect, but it's a good start
(function() {
var oldOpen = XMLHttpRequest.prototype.open;
window.openHTTPs = 0;
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
window.openHTTPs++;
this.addEventListener("readystatechange", function() {
if(this.readyState == 4) {
window.openHTTPs--;
}
}, false);
oldOpen.call(this, method, url, async, user, pass);
}
})();
相关推荐
最新文章