AJAX readyState

Whenever XMLHttpRequest object makes request to server this request goes through a cycle till server returns the response, XMLHttpRequest object have option to keep track of this request/readyState cycle using onreadystatechange property which triggers or fires a event as readyState changes.

The readyState property defines the current state of the XMLHttpRequest object.

Property Description
onreadystatechange It defines an event handler for an event that fires at every state change.
readyState Returns the status of the XMLHttpRequest. possible values for the readyState propery:
0: The request is not initialized
1: Server connection has been set up
2: The request has been sent
3: The request is in process
4: The request is completed and response is ready
status 200: “OK”
404: Page not found
statusText Returns the status as a string (e.g. “Not Found” or “OK”).

Using a Callback Function in AJAX