onreadystatechange
is a callback that is activated when a specific event occurs. This callback, onreadystate
, triggers when the request's ready state changes.
In short, onreadystate
Stores a function (or reference to a function) that is automatically executed whenever the readyState property changes
Now for the line
xmlhttp.readyState==4 && xmlhttp.status==200
readyState : Represents 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
Represents status
200: "OK"
404: Page not found
Therefore, the condition
xmlhttp.readyState==4 && xmlhttp.status==200
is true when the response is prepared without any issues
xmlhttp.responseText
holds the server's response.
So
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
modifies the HTML content of the element with the id
txtHint
to display the received response.
I hope all of the above information was clear!