0

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!

JAAulde
  • 18,787
  • 5
  • 52
  • 61
user2386986
  • 119
  • 5

0 Answers0