案例:ajax案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript">
4
var xmlhttp;
5
function loadXMLDoc(url,cfunc)
6
{
7
if (window.XMLHttpRequest)
8
  {// code for IE7+, Firefox, Chrome, Opera, Safari
9
  xmlhttp=new XMLHttpRequest();
10
  }
11
else
12
  {// code for IE6, IE5
13
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
14
  }
15
xmlhttp.onreadystatechange=cfunc;
16
xmlhttp.open("GET",url,true);
17
xmlhttp.send();
18
}
19
function myFunction()
20
{
21
loadXMLDoc("/jsjq/ajax/test1.txt",function()
22
  {
23
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
24
    {
25
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
26
    }
27
  });
28
}
29
</script>
30
</head>
31
<body>
32
33
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
34
<button type="button" onclick="myFunction()">通过 AJAX 改变内容</button>
35
36
</body>
37
</html>