实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<html><!DOCTYPE html>
2
<html>
3
<head>
4
<script>
5
function loadXMLDoc()
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("myDiv").innerHTML=xmlhttp.responseText;
21
    }
22
  }
23
xmlhttp.open("GET","/static/example/demo_get.php?t=" + Math.random(),true);
24
xmlhttp.send();
25
}
26
</script>
27
</head>
28
<body>
29
30
<h2>AJAX</h2>
31
<button type="button" onclick="loadXMLDoc()">Request data</button>
32
<p>Click the button several times to see if the time changes, or if the file is cached.</p>
33
<div id="myDiv"></div>
34
35
</body>
36
</html>
37