AJAX - The readyState property

The readyState property stores the current status of the server's response. Whenever readyState property changes, the onreadystatechange function is executed.

Possible values for the readyState property:

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

 

To get data from the web server we should first of all check the status of readyState property i.e. whether the request we made has been completed or not. So we add an If statement condition to the onreadystatechange function to test if the request we made is complete:

xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {
  // Now we can get data from the server's response
  }
}

 

http://www.botskool.com/programming-tutorials/ajax-tutorials/ajax-basic-tutorial