案例:ajax案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript">
4
function loadXMLDoc()
5
{
6
var xmlhttp;
7
var txt,x,i;
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
    xmlDoc=xmlhttp.responseXML;
21
    txt="";
22
    x=xmlDoc.getElementsByTagName("title");
23
    for (i=0;i<x.length;i++)
24
      {
25
      txt=txt + x[i].childNodes[0].nodeValue + "<br />";
26
      }
27
    document.getElementById("myDiv").innerHTML=txt;
28
    }
29
  }
30
xmlhttp.open("GET","/example/books.xml",true);
31
xmlhttp.send();
32
}
33
</script>
34
</head>
35
36
<body>
37
38
<h2>My Book Collection:</h2>
39
<div id="myDiv"></div>
40
<button type="button" onclick="loadXMLDoc()">获得我的图书收藏列表</button>
41
 
42
</body>
43
</html>