Activate your free membership today | Log-in

Monday, January 9th, 2006

Using the error codes from XHR calls

Category: Ajax, Editorial, Examples

<>p>Over at The Form Assembly they are discussing Treating the HTTP Status code right.

The main point of the article is the discussion of trapping various status codes, and doing smart things with them.

For example, a smart authentication handler could look something like:

switch (req.status) {
    case 200:
            // login ok, moving on...
            break;
    case 201:
            // was a registration.. will show a welcome message.
           showWelcomeMessage(req.reponseText);
           break;
    case 403:
           // authentication problem. The error message is in responseText
          showErrorMessage(req.responseText);
          break;
    default:
         // unknown error
         alert('There was a problem..');
}

Of course, there are browser quirks with status codes too, which is why you will see the following in the Prototype code:

  responseIsSuccess: function() {
    return this.transport.status == undefined
        || this.transport.status == 0
        || (this.transport.status >= 200 && this.transport.status < 300);
  }

Related Content:

  • XHR
    XMLHttpRequest, also called XHR, is an application program interface (API) that was first used by Microsoft in version 5.0 of its Internet Explorer...
  • XMLHttpRequest
    XMLHttpRequest, also called XHR, is an application program interface (API) that was first used by Microsoft in version 5.0 of its Internet Explorer...
  • Common Web application security exploits and how to stop them
    When examined at the granular level, Web applications nearly always have a number of security holes. At the 2009 Ajax Experience, Joe Walker, creator...
  • Ajax worm can hijack Web sites
    It's incredibly easy to create a worm using Ajax that controls all the communication between a user and the server, according to expert Anurag...
  • Troubleshooting ABAP code errors
    Need to display information to help diagnose an error with ABAP code? Learn how in this tip from a SearchSAP.com...

Posted by Dion Almaer at 12:42 am
Comment here

+++--
3.9 rating from 31 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.