I want to check if a page returns the status code 401. Is this possible?
Here is my try, but it only returns 0.
$.ajax({
url: "http://my-ip/test/test.php",
data: {},
complete: function(xhr, statusText){
alert(xhr.status);
}
});
I want to check if a page returns the status code 401. Is this possible?
Here is my try, but it only returns 0.
$.ajax({
url: "http://my-ip/test/test.php",
data: {},
complete: function(xhr, statusText){
alert(xhr.status);
}
});
Use the error callback.
For example:
jQuery.ajax({'url': '/this_is_not_found', data: {}, error: function(xhr, status) {
alert(xhr.status); }
});
Will alert 404
I think you should also implement the error function of the $.ajax method.
error(XMLHttpRequest, textStatus, errorThrown)Function
A function to be called if the request fails. The function is passed three arguments: The XMLHttpRequest object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "notmodified" and "parsererror".
$.ajax({
url: "http://my-ip/test/test.php",
data: {},
complete: function(xhr, statusText){
alert(xhr.status);
}
error: function(xhr, statusText, err){
alert("Error:" + xhr.status);
}
});
$.ajax({
url: "http://my-ip/test/test.php",
data: {},
error: function(xhr, statusText, errorThrown){alert(xhr.status);}
});