Created
December 19, 2016 15:57
-
-
Save hiulit/edb4fd2e82966f3c10ad007e627863e0 to your computer and use it in GitHub Desktop.
Automatically try AJAX request again on fail
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
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