XMLHttpRequest
has 5 readyState
s, and I only use 1 of them (the last one, 4
).
What are the others for, and what practical applications can I use them in?
readyState is both 2 (when the headers are received) and 4 (when the response has been downloaded) when any status code is returned.
State 4 means that the request had been sent, the server had finished returning the response and the browser had finished downloading the response content.
What is XHR readyState=3 ? Having the readyState with a value of 3 it means that the current state is LOADING . So when is a readyStateChange event for that state fired? Whenever an asynchrounous request does switch to the LOADING state.
The full list of readyState
values is:
State Description 0 The request is not initialized 1 The request has been set up 2 The request has been sent 3 The request is in process 4 The request is complete
(from https://www.w3schools.com/js/js_ajax_http_response.asp)
In practice you almost never use any of them except for 4.
Some XMLHttpRequest implementations may let you see partially received responses in responseText
when readyState==3
, but this isn't universally supported and shouldn't be relied upon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With