-
Notifications
You must be signed in to change notification settings - Fork 0
/
servo_xhr_abort_and_open.html
46 lines (42 loc) · 1.19 KB
/
servo_xhr_abort_and_open.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
<!DOCTYPE html>
<html>
<head>
<title>XHR abort and call open in onabort handler</title>
</head>
<body>
<h2>Events fired</h2>
<h3 id="events">
</h3>
<h2>Response</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"));
if (e.type == "abort") {
e.target.open("GET", "index.html", false);
}
}
function handleStateChange(e) {
if (this.readyState != 3) return;
resp = this.response;
this.onprogress = handleEvent;
this.onload = handleEvent;
this.onloadend = handleEvent;
this.onabort = handleEvent;
this.onreadystatechange = null;
this.abort();
document.getElementById("loaded").textContent += resp + "---aborted";
}
var req = new XMLHttpRequest();
req.onreadystatechange = handleStateChange;
req.open("GET", "index.html", true);
req.send();
</script>
</body>
</html>