运行下面的代码,该页面可以使用dayofweek和hourofday函数正常加载。但是在浏览器(Chrome)死机并给出错误消息后不久:net :: ERR_INSUFFICIENT_RESOURCES并引用了jQuery库和我的hourofday.js脚本。
几分钟后,它开始出现疯狂之类的错误,并冻结了。我什至无法重新加载页面。
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);
}
您可以在setInterval(hourofday, 6000);
hourofday()函数定义中调用函数!这意味着它将无限递归,自调用直到计算机内存耗尽。
只需将setInterval(...)语句移到函数定义之外即可。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句