2

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?

0

2 Answers 2

3

From the jQuery source code:

isSuccess = status >= 200 && status < 300 || status === 304;

So 2xx or 304 code is successful, anything else is failure.

Sign up to request clarification or add additional context in comments.

Comments

2

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

)}; typo at the end.
Yes, thanks, I'm using the method statusCode: {200 : onStatusCode200} passed to $.ajax.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.