Skip to content

Instantly share code, notes, and snippets.

@aeurielesn
Created April 27, 2012 17:23
Show Gist options
  • Save aeurielesn/2511005 to your computer and use it in GitHub Desktop.
Save aeurielesn/2511005 to your computer and use it in GitHub Desktop.
Retrying a jQuery.ajax() call
$.ajax({
url: '/echo/error/',
async: true,
// retryCount and retryLimit will let you retry a determined number of times
retryCount: 0,
retryLimit: 10,
// retryTimeout limits the total time retrying (in milliseconds)
retryTimeout: 10000,
// timeout for each request
timeout: 1000,
// created tells when this request was created
created : Date.now(),
error : function(xhr, textStatus, errorThrown ) {
this.retryCount++;
if (this.retryCount <= this.retryLimit && Date.now() - this.created < this.retryTimeout) {
console.log("Retrying");
$.ajax(this);
return;
}
}
});​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment