onreadystatechangeSets a function to receive data returned by
The following code defines a function for this var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { // code for receiving response data } |
||||||||||||
readyState PropertyThe readyState property defines the current state of the XMLHttpRequest object. Here are the possible values for the readyState propery:
You can also check the status of the response to see if it is Good.The next thing to check is the status code of the HTTP server
response. All the possible codes are listed on the W3C
site. For our purposes we are only interested in if (http_request.status == 200) { // perfect! } else { // there was a problem with the request, // for example the response may be a 404 (Not Found) // or 500 (Internal Server Error) response codes } |
||||||||||||
responseTextRetrieve text data returned by the server
xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { document.getElementById(‘formentry’).value = xmlhttp.responseText; } } |
||||||||||||
responseXMLRetrieve document data returned by the server
var xmldoc=xmlhttp.responseXML.documentElement; |
||||||||||||