Monday, January 9th, 2006

Using the error codes from XHR calls

Category: Ajax, Editorial, Examples

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...
    case 201:
            // was a registration.. will show a welcome message.
    case 403:
           // authentication problem. The error message is in responseText
         // 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);

Posted by Dion Almaer at 12:42 am
Comment here

3.8 rating from 36 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.