Ajax Tutorial: Monitoring Server Status

The XMLHTTPRequest object contains mechanisms by which we can know the progress of our Ajax request and determine when the information returned by the server is ready to use in our application.

The readyState property of the XMLHTTPRequest object gives you information from the server about the current state of a request you have made.

Possible Values

  • 0 Object is not initialized with data.
  • 1 Object is loading its data.
  • 2 Object has finished loading its data.
  • 3 User can interact with the object even though it is not fully loaded.
  • 4 Object is completely initialized.

When a server request is first made, the value of readyState is set to zero, meaning uninitialized.

As the server request progresses, data begins to be loaded by the server into the XMLHTTPRequest object, and the value of the readyState property changes accordingly, moving to 1 and then 2.

An object readyState value of 3, interactive, indicates that the object is sufficiently progressed so that certain interactivity with it is possible, though the process is not yet fully complete.

When the server request has completed fully and the object is available for further processing, the value of readyState changes finally to 4.

Leave a comment