Checking the XMLHttpRequest Object’s status property – 12
www.ajaxtraining.blogspot.com -Checking the XMLHttpRequest Object’s status property.We can check for an objects state to see where it’s at to decide if we can output the result or not, we can combine this with a test for the HTTP status of a download to see if it was successful, we can check for a value of 200 which means everything went ok. (a value of 404 would mean file not found just like normal HTTP status codes). To use the readystate property, just bang it on the end of the object name and put that in an ‘if’ statement. Ie… if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {do something} (the && means AND, so we check the readystate AND the status, if they are BOTH correct then execute the code in the curly brackets) To put that in the code of the last tutorial, replace the bit that outputs the message about the oranges box being collected with an anonymous function that is attached to the objects readystate. It’s not named an anonymous function because it has a secret identity, it is just a nice way of running a function with no name when a certain thing happens like the objects’ readystate being changed.

