您好我是java脚本的新手,如何使用而不是xmlhttp.onreadystatechange=function()
使用xmlhttp.readyState
检查函数状态setTimeout
,每10毫秒,我不知道如何每10毫秒执行一次。
答案 0 :(得分:1)
xmlhttp.onreadystatechange
都会被调用。
您不需要setTimeout
来检查xmlhttp.readyState
的值。
xmlhttp.onreadystatechange = function () {
console.log("readyState is now: " + xmlhttp.readyState);
}
你可以做类似的事情:
var state = 0;
xmlhttp.onreadystatechange = function () {
state = xmlhttp.readyState;
}
setInterval(function () {
console.log("readyState is now: " + state );
}, 100); // prints the readystate every 100ms
但我不明白为什么你需要像这样做。
答案 1 :(得分:0)
这将会每隔10毫秒不断递归一次:
(function readyStateCheck(){
//code to do the ready-state check
if (!someBreakingCondition){
setTimeout(readyStateCheck, 10);
}
})()