So what I am going to do is to send a bunch of requests at once, and wait for the response, something like this:
for(var i=0;i<n;i++){
x[i]=new XMLHttpRequest();
x[i].open("GET",url,true);
x[i].send();
x[i].onload=function(){
if(x[i].status==200){
//do something
} else {
//resend request
}
};
}
But clearly this doesn't work, since upon onload of x[i] (here i=1,2,...,n-1), the function invoked will always take i=n-1, because the loop indexed by i finishes before any of the x[i] finishes loading.
Thanks in advance!