Jquery provides methods for handling server response like done and fail. I'm wondering which status codes returned by the server are handled by callback passed to done and which are handled by callback passed to fail methods? Apperantly, the status code 200 is handled by done callback, and status code 500 is handled by fail callback. What about the others?
Add a comment
|
2 Answers
From the jQuery source code:
isSuccess = status >= 200 && status < 300 || status === 304;
So 2xx or 304 code is successful, anything else is failure.
Comments
Use:
if ( status >= 200 && status < 300 || status === 304 ) {
//success
}else{
//failed
}
You can even handle the response based on status.
request = $.ajax({
type: "GET",
url: url,
data: data,
complete: function(e, xhr, settings){
if(e.status === 200){
}else if(e.status === 304){
}else{
}
)};
)};
2 Comments
Jai
)}; typo at the end.Max Koretskyi
Yes, thanks, I'm using the method
statusCode: {200 : onStatusCode200} passed to $.ajax.