How do I know when the request started?

Browsers like Chrome can do 6ish concurrent requests .

If we try to simultaneously initiate more than 6 requests,

for (var i = 0; i < 11; 1++) {
  var oReq = new XMLHttpRequest();
  oReq.open('GET', URL);
  oReq.send();
}

then the browser will stand in line and execute them in batches of 6.

browser requests

Is it possible to tell when the request has moved from the waiting state to actually be executed?

The event onloadstartseems to fire when the request is added to the queue, and not when it starts loading.

+4
source share
1 answer

Have you looked at the readyState property for HttppRequest ? Perhaps this will cover your question.

XMLHttpRequest Object Properties

readyState:

XMLHttpRequest. 0 4:

0:

1:

2:

3:

4: ,

, , - :

for (var i = 0; i < 11; 1++) {
  var oReq = new XMLHttpRequest();
  oReq.open('GET', URL);
  oReq.send();

  oReq.onreadystatechange = function(){
    if (oReq.readyState == 4 && oReq.status == 200) {   
      //do something like an alert
      //you can get rid of the oReq.status if you want and 
      //just track the readyState (0-4)
    };
  };
}
+2

All Articles