forked from hehos/javascriptAdvanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXHRErrorEventExample01.htm
More file actions
executable file
·55 lines (48 loc) · 1.84 KB
/
Copy pathXHRErrorEventExample01.htm
File metadata and controls
executable file
·55 lines (48 loc) · 1.84 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
<!DOCTYPE html>
<html>
<head>
<title>XHR Error Event Example</title>
</head>
<body>
<p>This example must be run on a server to work properly and will only work in Firefox, Safari, and Opera.</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){
if ((xhr.status >= 200 && xhr.status < 300) ||
xhr.status == 304){
alert(xhr.responseText);
} else {
alert("Request was unsuccessful: " + xhr.status);
}
};
xhr.onerror = function(event){
alert("Error!");
};
xhr.open("get", "altevents.php", true);
xhr.send(null);
</script>
</body>
</html>