forked from johnkpaul/jquery-ajax-retry
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
77 lines (74 loc) · 2.53 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jQuery Ajax Retry Test Suite</title>
<!-- Load local jQuery, removing access to $ (use jQuery, not $). -->
<script src="../libs/jquery/jquery.js"></script>
<script>
jQuery.noConflict();
</script>
<!-- Load local lib and tests. -->
<script src="../src/jquery.ajax-retry.js"></script>
</head>
<body>
<script>
jQuery(function ($) {
/* BASIC USAGE */
/*
$.ajax({
url: "https://httpstat.us/200?sleep=2000",
timeout: 1000,
})
.retry({
statusCodes: [408], // ONLY retry if these status codes are returned in the response.
times: 3, // This is the total number of attempts, NOT the number of retries.
timeout: 500, // This is the amount of time before Jquery just says a timeout occurred.
})
.fail(function (jqxhr, textStatus, errorThrown) {
console.log("Status: ", textStatus);
console.log("StatusCode: ", jqxhr.status);
console.log("Error: ", errorThrown);
});
*/
/* EXPONENTIAL USAGE */
var retryCallback = function (currentAttempt, totalAttempts, msUnitlNextAttempt) {
$("#attempts").html(currentAttempt);
$("#total").html(totalAttempts);
if (msUnitlNextAttempt) {
$("#next").html(
"Next attempt in " + msUnitlNextAttempt + " milliseconds."
);
} else {
$("#next").html("No more attempts");
}
};
$.ajax({
url: "https://httpstat.us/408",
timeout: 10000,
})
.retry({
exponential: true, // Exponential backoff on retries (defaults to false).
onRetry: retryCallback,
statusCodes: [408], // ONLY retry if these status codes are returned in the response.
times: 3, // This is the total number of attempts, NOT the number of retries.
timeout: 1000, // The base delay for the exponential backoff calculations.
})
.fail(function (jqxhr, textStatus, errorThrown) {
$("#next").html("");
console.log("Status: ", textStatus);
console.log("StatusCode: ", jqxhr.status);
console.log("Error: ", errorThrown);
});
});
</script>
<h1>jQuery Ajax Retry Test</h1>
<p>
Attempt
<span id="attempts">1</span>
of
<span id="total"></span>.
<span id="next"></span>
</p>
</body>
</html>