Hi, I am confuse of this jquery.ajax,how can i alert this three parameters if the request get fails, i want to know what the error causes and to alert this error.
like errorparsing,error, pagenotfound…etc…
by reading this
error
Type: Function( jqXHR jqXHR, String textStatus, String errorThrown )
A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, 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”, “abort”, and “parsererror”. When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as “Not Found” or “Internal Server Error.” As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: This handler is not called for cross-domain script and JSONP requests. This is an Ajax Event.
i tried this
$.ajax({
type: 'post',
url: 'notfoundpage.php',
error: function(jqXHR,textStatus,errorThrown ){
//here i want to alert those 3 parameters that causes the error.
//I tried like this
alert(jqXHR);
alert(textStatus);
alert(errorThrown);
},
.....
.....
});
Hi paul, thank you for the reply what about the parse error do i need to delclare each of them like this
$.ajax({
type: ‘post’,
url: ‘notfoundpage.php’,
error: function(jqXHR,textStatus,errorThrown ){
yes, I tried the parse error message by using the textStatus, I tried to make the url as invalid so that it will alert “page not found”,but if i will just alert the textStatus it will not display the page not found, my point is how can i know or to alert message error that causes my ajax request to fail…
alert(jqXHR.status);
, i could not know what error message causes my ajax fails
so if i will going do like this,after changing the correct url.
$.ajax({
url:'validpage.php',
data: {id:1},
error: function(jqXHR,textStatus,errorThrown ){
alert(jqXHR.status);
alert(textStatus); // so this will be alerted if ever i have parseerror,or etc ?
},
});