views:

29

answers:

1

I am doing an AJAX request. In my onFail event of the Request I catch the XHR object.
What is the name of the member in this object that holds the code.
For that mater, I could not find a documentation that shows the list of members in that object.

A: 

just console.info this in the callback onFailure - this.status contains the http error response. this.xhr contains more about the request and extended responses.

http://www.jsfiddle.net/dimitar/NF2jz/365/

new Request({
    url: '/secho/html/',
    data: {
        html: "<p>Text echoed back to request</p>" + "<script type='text/javascript'>$('target').highlight();<\/script>",
        delay: 3
    },
    method: 'post',
    onFailure: function() {
        var error = "Error " + this.status;
        switch (this.status) {
            case 404:
                error = "Document not found (404)";
            break;
            case 301:
                error = "Object moved permanently (301 redirect)";
            break;
            case 302:
                error = "Object moved temporarliy (302 redirect)";
            break;
        }
        alert(error);
    }
}).send();
Dimitar Christoff