我试图让 setTimeout 在 15 秒后重新运行它内部的函数,它不是等待 15 秒,而是在一个恒定循环中执行它。
这是我当前的代码
function checkSession(x) {
http.abort();
http.open("GET", siteURL+"processes/ajax.php?call=check_session&string="+x+"&new="+Math.random(), true);
http.onreadystatechange = function() {
if(http.readyState == 4) {
if(http.responseText == true) {
updateSession(x);
} else {
setTimeout(checkSession(x),15000);
}
}
}
http.send(null);
}
我没有看到代码本身有任何问题,唯一错误的是它只是在执行一个恒定循环而没有等待“15000”毫秒。