Skip to content

Instantly share code, notes, and snippets.

@lucassmagal
Last active December 19, 2015 01:38
Show Gist options
  • Save lucassmagal/5876911 to your computer and use it in GitHub Desktop.
Save lucassmagal/5876911 to your computer and use it in GitHub Desktop.
function do_ajax(args, dfd, attempt) {
dfd || (dfd = $.Deferred());
attempt || (attempt = 1);
$.ajax(args).then(dfd.resolve, function(xhr, text_status, error_thrown) {
console.error('Fail on attempt', attempt + '!', 'Text status', text_status);
attempt++;
if(attempt > 3) {
dfd.reject(xhr, text_status, error_thrown);
} else {
do_ajax(args, dfd, attempt);
}
});
return dfd.promise();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment