Reputation: 21
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:
My question is: if readyState changed to 1 but never changed to 2/3/4, was my POST request actually:
Note this is on IE 11.
Thanks,
Upvotes: 1
Views: 1881
Reputation: 53
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.
Upvotes: 1