【发布时间】:2018-10-26 17:12:30
【问题描述】:
我的代码在 Chrome 和 Safari 中运行,但在 FF 中挂起。
我删除了不必要的代码部分。
我使用控制台命令来显示第一个循环有多远,它会在 xhr 打开和发送命令之前执行第二个日志。
如果打开/发送命令存在,则循环只发生一次,如果我删除打开/发送命令,则循环成功完成。
目前正在使用 FF 62nightly,但自从 Quantum 推出以来,这个问题一直困扰着我,我现在正试图弄清楚为什么它不能正常工作。
for (i = 0; i < length; i++) {
(function(i) {
// new XMLHttpRequest
xhr[i] = new XMLHttpRequest();
// gets machine url from href tag
url = rows[i].getElementsByTagName("td")[0].getElementsByTagName('a')[0].getAttribute('href');
// Insert the desired values at the end of each row;
// will try to make this customizable later as well
insertVNC[i] = rows[i].insertCell(-1);
insertSerial[i] = rows[i].insertCell(-1);
insertVersion[i] = rows[i].insertCell(-1);
insertFreeDiskSpace[i] = rows[i].insertCell(-1);
// the fun part: this function takes each url, loads it in the background,
// retrieves the values needed, and then discards the page once the function is complete;
// In theory you could add whatever you want without taking significantly longer
// as long as it's on this page
console.log(i);
xhr[i].onreadystatechange = function() {
if (xhr[i].readyState == 4 && xhr[i].status == 200) {
}
};
//"Get" the "Url"... true means asyncrhonous
console.log(url);
xhr[i].open("GET", url, true);
xhr[i].send(null);
})(i); //end for loop
}
【问题讨论】:
-
i大概有多大?例如,如果您一次尝试 100 个连接,则不同的浏览器可能有不同的限制。length只有 1 或 2 时还会发生这种情况吗? -
最多说 40。是的,当 i 为 1 或 2 时它会这样做
-
还建议使用调试器单步执行。您的 Web 控制台中是否有任何错误?
-
这是一个在 FF 60.0 中适合我的小提琴:jsfiddle.net/khrismuc/rfm5fcw1
-
这是一个扩展的事实可能与潜在的解决方案密切相关。如果是这样,您可能希望适当地标记您的问题。
标签: javascript firefox xmlhttprequest