Hi I am new in java script ,How I can use instead of xmlhttp.onreadystatechange=function()
check the state of function, xmlhttp.readyState
,every 10 milliseconds, with setTimeout
,i don't know how to do it every 10 milliseconds.
thank you.
Hi I am new in java script ,How I can use instead of xmlhttp.onreadystatechange=function()
check the state of function, xmlhttp.readyState
,every 10 milliseconds, with setTimeout
,i don't know how to do it every 10 milliseconds.
thank you.
xmlhttp.onreadystatechange
will be called whenever it changes state.
You don't need a setTimeout
to check the value of xmlhttp.readyState
.
xmlhttp.onreadystatechange = function () {
console.log("readyState is now: " + xmlhttp.readyState);
}
You could do something like:
var state = 0;
xmlhttp.onreadystatechange = function () {
state = xmlhttp.readyState;
}
setInterval(function () {
console.log("readyState is now: " + state );
}, 100); // prints the readystate every 100ms
But I don't see why you'd need to do it like this.
This will function will continually recurse every 10ms:
(function readyStateCheck(){
//code to do the ready-state check
if (!someBreakingCondition){
setTimeout(readyStateCheck, 10);
}
})()