-
Notifications
You must be signed in to change notification settings - Fork 0
/
servo_xhr_abort_recursive.html
44 lines (40 loc) · 1.15 KB
/
servo_xhr_abort_recursive.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
<!DOCTYPE html>
<html>
<head>
<title>XHR abort in ready state handler and perform synchronous send</title>
</head>
<body>
<h2>Events fired</h2>
<h3 id="events">
</h3>
<h2>Response Body</h2>
<span id="loaded">
</span>
<script>
function handleEvent(e) {
var parent = document.getElementById("events");
var event = document.createElement("span");
event.textContent += "Event Type: " + e.type;
event.textContent += "; Ready State: " + e.target.readyState;
parent.appendChild(event);
parent.appendChild(document.createElement("br"));
}
function handleStateChange(e) {
if (e.target.readyState != 4) return;
this.onprogress = handleEvent;
this.onload = handleEvent;
this.onloadend = handleEvent;
resp = this.response;
this.abort();
document.getElementById("loaded").textContent += resp + "---aborted";
this.onreadystatechange = null;
this.open("GET", "index.html", false);
this.send();
}
var req = new XMLHttpRequest();
req.onreadystatechange = handleStateChange;
req.open("GET", "index.html", true);
req.send();
</script>
</body>
</html>