javascript 运行 jQuery 脚本发出 ajax 请求 2 分钟后出现错误 net::ERR_INSUFFICIENT_RESOURCES
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26447605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error net::ERR_INSUFFICIENT_RESOURCES after 2 minutes of running jQuery script making ajax requests
提问by Daniel
Running the code below, the page loads fine with the dayofweek and hourofday functions. But shortly after the browser (Chrome) freezes up and gives the error : net::ERR_INSUFFICIENT_RESOURCES and refers to the jQuery library and my hourofday.js script.
运行下面的代码,页面可以通过 dayofweek 和 hourofday 函数正常加载。但是在浏览器 (Chrome) 冻结并给出错误后不久:net::ERR_INSUFFICIENT_RESOURCES 并引用了 jQuery 库和我的 hourofday.js 脚本。
After a few mins it starts getting errors like crazy and it freezes. I can't even reload the page.
几分钟后,它开始出现疯狂的错误并冻结。我什至无法重新加载页面。
function dayofweek(){
$.ajax({
url: "dayofweek.php",
type: "POST",
dataType: "xml",
success: function (xml){
var day = $(xml).find('day').first().text();
$("#dayofweek").html(day);
},
error: function (xhr, status) {
},
complete: function (xhr, status) {
}
});
}
function hourofday(){
$.ajax({
url: "hourofday.php",
type: "POST",
dataType: "xml",
success: function (xml){
var response = $(xml).find('response').first().text();
$("#hourofday").html(response);
},
error: function (xhr, status) {
},
complete: function (xhr, status) {
}
});
setInterval(dayofweek, 6000);
setInterval(hourofday, 6000);
}
回答by Leonardo Gonzalez
You have the setInterval(hourofday, 6000);
function call INSIDE the hourofday() function definition! This means that it will infinitely recurse, calling itself until your computer runs out of memory.
您setInterval(hourofday, 6000);
在 hourofday() 函数定义中有函数调用!这意味着它将无限递归,调用自己直到您的计算机内存不足。
Just move the setInterval(...) statements OUTSIDE of the function definitions.
只需将 setInterval(...) 语句移到函数定义之外。