-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXHRAlternateEventsExample01.htm
More file actions
executable file
·57 lines (51 loc) · 1.95 KB
/
Copy pathXHRAlternateEventsExample01.htm
File metadata and controls
executable file
·57 lines (51 loc) · 1.95 KB
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
<!DOCTYPE html>
<html>
<head>
<title>XHR Alternate Events Example</title>
</head>
<body>
<p>This example must be run on a server to work properly and will only work in Firefox.</p>
<div id="status"></div>
<script type="text/javascript">
function createXHR(){
if (typeof XMLHttpRequest != "undefined"){
return new XMLHttpRequest();
} else if (typeof ActiveXObject != "undefined"){
if (typeof arguments.callee.activeXString != "string"){
var versions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0",
"MSXML2.XMLHttp"];
for (var i=0,len=versions.length; i < len; i++){
try {
var xhr = new ActiveXObject(versions[i]);
arguments.callee.activeXString = versions[i];
return xhr;
} catch (ex){
//skip
}
}
}
return new ActiveXObject(arguments.callee.activeXString);
} else {
throw new Error("No XHR object available.");
}
}
var xhr = createXHR();
xhr.onload = function(event){
alert(xhr.responseText);
alert(xhr.status);
};
xhr.onerror = function(event){
alert("Error: " + xhr.status);
};
xhr.onprogress = function(event){
var statusDiv = document.getElementById("status");
statusDiv.innerHTML = "Received " + event.position + " of " + event.totalSize;
};
xhr.onloadend = function(event){
alert("End!");
};
xhr.open("get", "example.txt", true);
xhr.send(null);
</script>
</body>
</html>