CARVIEW |
Select Language
HTTP/2 301
location: https://raw.githubusercontent.com/johnkpaul/jquery-ajax-retry/master/dist/jquery.ajax-retry.js
accept-ranges: bytes
age: 0
date: Sun, 27 Jul 2025 10:41:15 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210065-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753612875.507382,VS0,VE1206
vary: Accept-Encoding
x-fastly-request-id: 6a6e2edf8175abcb4243bd0855fa4afce8fc6317
content-length: 0
HTTP/2 200
cache-control: max-age=300
content-security-policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
content-type: text/plain; charset=utf-8
etag: W/"c27a7c389964c26aa1988ee66b3b2da5ab33646f1f98a22720537e8685fe20b6"
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
x-frame-options: deny
x-xss-protection: 1; mode=block
x-github-request-id: E929:1A240A:1DD1A8:4E19F6:68860245
content-encoding: gzip
accept-ranges: bytes
date: Sun, 27 Jul 2025 10:41:16 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210044-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753612876.768327,VS0,VE250
vary: Authorization,Accept-Encoding
access-control-allow-origin: *
cross-origin-resource-policy: cross-origin
x-fastly-request-id: 239316375187e6f2cdb79e869647f5bc3bb08d46
expires: Sun, 27 Jul 2025 10:46:16 GMT
source-age: 0
content-length: 1060
/*
* jquery.ajax-retry
* https://github.com/johnkpaul/jquery-ajax-retry
*
* Copyright (c) 2012 John Paul
* Licensed under the MIT license.
*/
(function(factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
})(function($) {
// enhance all ajax requests with our retry API
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
jqXHR.retry = function(opts) {
if(opts.timeout) {
this.timeout = opts.timeout;
}
if (opts.statusCodes) {
this.statusCodes = opts.statusCodes;
}
return this.pipe(null, pipeFailRetry(this, opts));
};
});
// generates a fail pipe function that will retry `jqXHR` `times` more times
function pipeFailRetry(jqXHR, opts) {
var times = opts.times;
var timeout = jqXHR.timeout;
// takes failure data as input, returns a new deferred
return function(input, status, msg) {
var ajaxOptions = this;
var output = new $.Deferred();
var retryAfter = jqXHR.getResponseHeader('Retry-After');
// whenever we do make this request, pipe its output to our deferred
function nextRequest() {
$.ajax(ajaxOptions)
.retry({times: times - 1, timeout: opts.timeout, statusCodes: opts.statusCodes})
.pipe(output.resolve, output.reject);
}
if (times > 1 && (!jqXHR.statusCodes || $.inArray(input.status, jqXHR.statusCodes) > -1)) {
// implement Retry-After rfc
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.37
if (retryAfter) {
// it must be a date
if (isNaN(retryAfter)) {
timeout = new Date(retryAfter).getTime() - $.now();
// its a number in seconds
} else {
timeout = parseInt(retryAfter, 10) * 1000;
}
// ensure timeout is a positive number
if (isNaN(timeout) || timeout < 0) {
timeout = jqXHR.timeout;
}
}
if (timeout !== undefined){
setTimeout(nextRequest, timeout);
} else {
nextRequest();
}
} else {
// no times left, reject our deferred with the current arguments
output.rejectWith(this, arguments);
}
return output;
};
}
});