-
Notifications
You must be signed in to change notification settings - Fork 0
/
servo_xhr_timeout.html
42 lines (37 loc) · 1.06 KB
/
servo_xhr_timeout.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
<!DOCTYPE html>
<html>
<head>
<title>Servo - XHR Race condition demo</title>
</head>
<body>
<h3 id="dummy">
</h3>
<h3 id="headers">
</h3>
<h3 id="loaded">
</h3>
<script>
function handleEvent(e) {
state = e.target.readyState
if (state == 2)
document.getElementById("headers").textContent = "Received headers";
if (state == 3 || state == 4)
document.getElementById("loaded").textContent = e.target.response;
}
function handleTimeout(e) {
document.getElementById("dummy").textContent += "Timed out."
}
var timeout = window.prompt("Enter a timeout value: ", "600");
timeout = parseInt(timeout);
var req = new XMLHttpRequest();
req.onreadystatechange = handleEvent;
req.timeout = timeout;
req.ontimeout = handleTimeout;
req.open("GET", "testa.txt", true);
req.send();
var startTime = new Date().getTime();
while (new Date().getTime() < startTime + timeout * 2);
document.getElementById("dummy").textContent += "Timeout Value: " + timeout;
</script>
</body>
</html>