Bill
Bill

Reputation: 5678

How to find the ajax status with jQuery 1.2.6

I'm using jQuery 1.2.6 (I know it's old, but I don't have a choice) I need to check the status of my ajax calls. I either want to use:

statusCode, or I could even use error(jqXHR, textStatus, errorThrown), except that textStatus, errorThrown and statusCode, aren't in my jQuery version.

Basically what I have to do, is know if the ajax call was aborted, or had an error for another reason. Any ideas how I can do this?

Upvotes: 0

Views: 989

Answers (1)

Kevin B
Kevin B

Reputation: 95048

you could get the status text from the error callback:

$.ajax({
    url: "/foo",
    dataType: "text",
    error: function(obj){
        alert(obj.status + "\n" + obj.statusText);
    }
});

http://jsfiddle.net/jnXQ4/

you can also get it from the complete callback if the request resulted in an error.

Edit: the ajax request also returns the XMLHttpRequest which you can then bind events to, though I'm not sure how cross-browser it is.

var request = $.ajax(options);
request.onabort = function(){
  alert('aborted');
}

Upvotes: 1

Related Questions