Archive for the ‘jquery’ Category

jQuery $.ajax statusCode and statusText

Wednesday, February 8th, 2012

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);