-
-
Save jerkovicl/7fd836006f49ade63612 to your computer and use it in GitHub Desktop.
Retrying a jQuery.ajax() call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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