实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<html><!DOCTYPE html>
2
<html>
3
<head>
4
<script>
5
function loadXMLDoc(url)
6
{
7
var xmlhttp;
8
if (window.XMLHttpRequest)
9
  {// code for IE7+, Firefox, Chrome, Opera, Safari
10
  xmlhttp=new XMLHttpRequest();
11
  }
12
else
13
  {// code for IE6, IE5
14
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
15
  }
16
xmlhttp.onreadystatechange=function()
17
  {
18
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
19
    {
20
    document.getElementById('A1').innerHTML=xmlhttp.status;
21
    document.getElementById('A2').innerHTML=xmlhttp.statusText;
22
    document.getElementById('A3').innerHTML=xmlhttp.responseText;
23
    }
24
  }
25
xmlhttp.open("GET",url,true);
26
xmlhttp.send();
27
}
28
</script>
29
</head>
30
<body>
31
32
<h2>Retrieve data from XML file</h2>
33
<p><b>Status:</b><span id="A1"></span></p>
34
<p><b>Status text:</b><span id="A2"></span></p>
35
<p><b>Response:</b><span id="A3"></span></p>
36
<button onclick="loadXMLDoc('/static/example/cd_catalog.xml')">Get XML data</button>
37
38
</body>
39
</html>