1

My JS code is sending out requests and monitors "xhr.onreadystatechange". Sometimes it will collect the following logs, which are expected:

timestamp   event   method  readyState  status
1/9/2018 9:08:43.474    xhr_readystatechange    POST    1   0
1/9/2018 9:08:46.432    xhr_readystatechange    POST    2   200
1/9/2018 9:08:46.432    xhr_readystatechange    POST    3   200
1/9/2018 9:08:46.433    xhr_readystatechange    POST    4   200

Other times it will collect the following logs, which are not expected: (in this case, readyState never changed to 2 within the 22 seconds before my app timed out)

timestamp   event   method  readyState  status
1/11/2018 21:36:25.390  xhr_readystatechange    POST    1   0
1/11/2018 21:36:47.249  localSend           failed

I understand that:

  • readyState 1 means xhr.open is called but xhr.send has not been called
  • readyState 2 means xhr.send has been called and response header is received

My question is: if readyState changed to 1 but never changed to 2/3/4, was my POST request actually:

  • never sent on the wire (xhr.send has not been called)? If so, what might have caused this? Could the request be dropped by xhr.send inside the browser JS engine?
  • or, sent to the server but got stuck there for whatever reason (so response header is not ready).

Note this is on IE 11.

Thanks,

yoduoy
  • 21
  • 6
  • Better to show code rather than logs in this case, but if it occurs randomly, it is probably server side issue.. [Maybe related](https://stackoverflow.com/questions/4401608/javascript-xmlhttprequest-randomly-stuck-at-ready-state-1) – bigless Jan 12 '18 at 00:44

1 Answers1

1

If readyState is 1, it only means that the method open was called. This can't say if the request was sent or not. If the method send was called, the client will make a establishment with the server. If the connection failed, the event onerror will be fired. So try to see the error message, and it will says the reason.

To answer the question. It is possible that send was not called if readyState is 1, but if you want to know the method send was called or not, you should see the code, and log the message when the method send was called. Also, if readyState is 1, and you've checked the method send was called, it means that the client started to make the establishment with the server, so it could be that the packet is on the way, and it could got stuck for some reason.

In a nutshell, readyState can't tell if the method send was called or not. The way to check that is to see the code, and make sure that the method send was called or not.

btooom
  • 53
  • 4