Skip to content

Instantly share code, notes, and snippets.

@hiulit
Created December 19, 2016 15:57
Show Gist options
  • Save hiulit/edb4fd2e82966f3c10ad007e627863e0 to your computer and use it in GitHub Desktop.
Save hiulit/edb4fd2e82966f3c10ad007e627863e0 to your computer and use it in GitHub Desktop.
Automatically try AJAX request again on fail
var attempts;
function doAjaxRequest() {
attempts = 0;
doAjaxRequestLoop();
}
function doAjaxRequestLoop() {
attempts += 1;
if (attempts > 10) {
alert('too many attempts.');
return;
}
$.ajax({ // do your request
error: function (error) {
doAjaxRequestLoop();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment