I've a server that returns HTTP status code 200, 201, and 202 from the same url. In Chrome, I've confirmed with the Network debugging panel that the Status Code is what I expect it to be (i.e. 200, 201 or 202). I rely on that status code to determine the next step.
I'd expect that the callbacks for jQuery (version 1.5.2) AJAX requests to set jqxhr.status to the status code that the server sends. However, the status code is always 200, even if the code sent by the server is 201 or 202.
In other words, the following code prints Code: 200 regardless of what the server sends.
$.get(url, {}, function (data, textStatus, xhr ) {
alert("Code: " + xhr.status);
});
Why is this happening, and more importantly, how can one get the actual status code in a jQuery AJAX callback for $.get or $.ajax?
Thank you for reading.
GETrequest?$.ajaxand report the status in both the code handler and success.statusCodeandsuccesshandlers. This seems to be a strange truncation of the status code - I'd think there'd be some indication in e.g. github.com/jquery/jquery/blob/master/src/ajax.js, but I don't see anything that would obviously change thejqXHR.statusto 200 from 201/202.