Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the different readystates in XMLHttpRequest mean, and how can I use them?

XMLHttpRequest has 5 readyStates, 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?

like image 783
Marius Avatar asked Mar 11 '09 00:03

Marius


People also ask

What is the meaning of readyState 2 in XMLHttpRequest?

readyState is both 2 (when the headers are received) and 4 (when the response has been downloaded) when any status code is returned.

What is the meaning of Xmlhttp readyState == 4?

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 does readyState 3 mean?

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.


1 Answers

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.

like image 108
Kieron Avatar answered Sep 30 '22 22:09

Kieron