Skip to content

Instantly share code, notes, and snippets.

View marketinview's full-sized avatar

Market In View marketinview

View GitHub Profile
@yairEO
yairEO / jQuery.ajaxRetry.js
Last active January 12, 2022 14:55
jQuery AJAX smart retry
// enhance the original "$.ajax" with a retry mechanism
$.ajax = (($oldAjax) => {
// on fail, retry by creating a new Ajax deferred
function check(a,b,c){
var shouldRetry = b != 'success' && b != 'parsererror';
if( shouldRetry && --this.retries > 0 )
setTimeout(() => { $.ajax(this) }, this.retryInterval || 100);
}
return settings => $oldAjax(settings).always(check)