Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

Checking the XMLHttpRequest Object's status property - 12

Loading...

Sign in or sign up now!
3,329
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Mar 9, 2008

http://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.

Category:

Education

Tags:

License:

Standard YouTube License

  • likes, 0 dislikes

Link to this comment:

Share to:

All Comments (0)

Sign In or Sign Up now to post a comment!
Loading...

0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more