案例:XML案例     状态:不可编辑再运行    进入竖版
 运行结果 
x
 
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 Firefox, Opera, IE7, 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('T1').innerHTML=xmlhttp.responseText;
35
    }
36
  else
37
    {
38
    alert("Problem retrieving data:" + xmlhttp.statusText);
39
    }
40
  }
41
}
42
</script>
43
</head>
44
45
<body onload="loadXMLDoc('/example/xdom/test_xmlhttp.txt')">
46
<div id="T1" style="border:1px solid black;height:40;width:300;padding:5"></div><br />
47
<button onclick="loadXMLDoc('/example/xdom/test_xmlhttp2.txt')">Click</button>
48
</body>