案例:XML案例     状态:可编辑再运行    进入竖版
 运行结果 
x
<button onclick="loadXMLDoc('/example/xdom/note.xml')">Get XML</button>
 
1
<html>
2
<head>
3
<script type="text/javascript">
4
var xmlhttp;
5
function loadXMLDoc(url)
6
{
7
xmlhttp=null;
8
if (window.XMLHttpRequest)
9
  {// code for IE7, Firefox, Opera, etc.
10
  xmlhttp=new XMLHttpRequest();
11
  }
12
else if (window.ActiveXObject)
13
  {// code for IE6, IE5
14
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
15
  }
16
if (xmlhttp!=null)
17
  {
18
  xmlhttp.onreadystatechange=state_Change;
19
  xmlhttp.open("GET",url,true);
20
  xmlhttp.send(null);
21
  }
22
else
23
  {
24
  alert("Your browser does not support XMLHTTP.");
25
  }
26
}
27
28
function state_Change()
29
{
30
if (xmlhttp.readyState==4)
31
  {// 4 = "loaded"
32
  if (xmlhttp.status==200)
33
    {// 200 = "OK"
34
    document.getElementById('A1').innerHTML=xmlhttp.status;
35
    document.getElementById('A2').innerHTML=xmlhttp.statusText;
36
    document.getElementById('A3').innerHTML=xmlhttp.responseText;
37
    }
38
  else
39
    {
40
    alert("Problem retrieving XML data:" + xmlhttp.statusText);
41
    }
42
  }
43
}
44
</script>
45
</head>
46
47
<body>
48
<h2>Using the HttpRequest Object</h2>