There are 3 important properties of the XMLHttpRequest object

AJAX onreadystatechange

The onreadystatechange property stores the function that has to run when we receive the response from the server or web service.

AJAX readyState

The readyState property stores the state of the XMLHttpRequest object.

Its values can be:

0: request not initialized

1: server connection established

2: request received

3: processing request

4: request finished and response is ready

AJAX status

The status property indicates whether the request was successfully executed (200) or if there is an error (404)

Possible values for status

200: "OK"

404: Page not found

When readyState is 4 and status is 200, the response is ready.

Example of using events and properties:

xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } }