2

There are situations when an ajax request fails and there is no reason to make a new attempt to re-send the last request, eg when getting an error code 404, 405 etc - because a new attempt will result always in the same.

But in some situations as server busy, timeout, and others(?) would can be interesting to have a routine that keeps trying to resend the request, and when it reaches a limit, display a message to the user if they want to stop the attempts - like in gmail when user have his connection lost.

Below I have the beginning of what I need.

$.ajaxSetup({
   error: function(msg,e) { 
      console.warn(msg); // Example: "NetworkError: 405 Method Not Allowed ..."
      console.warn(e); // Exception obj
   }
});

Generically beyond busy server, timeout and what else case I could do a retry? And if so, how I can get the error code and the last request from ajax (URL, post data...)?

Ragen Dazs
  • 2,115
  • 3
  • 28
  • 56
  • It's an interesting question. Something you should also consider when doing this is to make sure that the jquery deferred object generated for these requests also doesn't return until the retry counts. So if you're chaining or waiting for requests to finish, it shouldn't be marked as finished until it either succeeds or retries too many times that it reaches the limit. You'd need to wrap your deferred in another layer of deferred along with the retry counter. – Eli Gassert Jan 30 '13 at 17:06
  • @EliGassert it's the point! – Ragen Dazs Jan 30 '13 at 17:07
  • It'll be a cool feature once done. I don't have anything else to offer other than my first comment, but if you ever create this I'd love to see a solution :) Good luck – Eli Gassert Jan 30 '13 at 17:11
  • 1
    I found the startup http://stackoverflow.com/a/9446122/1596489 – Ragen Dazs Jan 30 '13 at 19:49

0 Answers0