in a while loop of http requests when sending an HTTP request i want the next request wait a moment to let me get the response from the previous one.
Is a setTimeout
function will help ?
here is the code :
while(i <= 50){
http.onreadystatechange = function(){
if(http.readyState == 4){
getPosts(http.responseText , i);
//alert(http.responseText);
}
}
http.open("get","../php/php.php?q=getBody&id=comment"+i);
http.send();
//sleep(0); this another function in i send a request to php file to make asleep
i++;
}
Also here is a photo for what happen in firebug: firebug error photo