Skip to content

Instantly share code, notes, and snippets.

@mdcarmo
Created July 24, 2018 11:42
Show Gist options
  • Save mdcarmo/d58d6c84585fc519a34df427e51705d1 to your computer and use it in GitHub Desktop.
Save mdcarmo/d58d6c84585fc519a34df427e51705d1 to your computer and use it in GitHub Desktop.
Retry an AJAX and JQuery
$.ajax({
url : 'someurl',
type : 'POST',
data : ....,
tryCount : 0,
retryLimit : 3,
success : function(json) {
//do something
},
error : function(xhr, textStatus, errorThrown ) {
if (textStatus == 'timeout') {
this.tryCount++;
if (this.tryCount <= this.retryLimit) {
//try again
$.ajax(this);
return;
}
return;
}
if (xhr.status == 500) {
//handle error
} else {
//handle error
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment