onreadystatechange
is a callback. It gets triggered when a particular event happens. onreadystate
is happens when the requests ready state changes.
In short onreadystate
Stores a function (or the reference of a function) to be called automatically each time the readyState property changes
Now for the line
xmlhttp.readyState==4 && xmlhttp.status==200
readyState : Holds the status of the XMLHttpRequest.
Changes from 0 to 4:
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready
And status
Holds status
200: "OK"
404: Page not found
So xmlhttp.readyState==4 && xmlhttp.status==200
condition is true when the response is ready and there is no issues
xmlhttp.responseText
contains the response sent from the server.
So document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
changes the HTML of the element with id txtHint
to the response that was received.
Hope all the above made sense!!!