jQuery $.ajax statusCode and statusText

It is bit tricky to get jQuery $.ajax call exact status. Turns out that error function first parameter has function statusCode() which returns object that contains status parameters. See code below and you will understand how to get hold of the statuscode and statustext values.

        type : 'POST',
        url : loginUrl,
        data : {
            username : $('input[name=username]').val(),
            password : $('input[name=password]').val()
        success : onSuccess,
        error : function (xhr, text, err) {            
            alert(xhr.statusCode().status+" "+xhr.statusCode().statusText);

Leave a Reply

Your email address will not be published.