实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<script>
5
var xmlhttp;
6
function loadXMLDoc(url,cfunc)
7
{
8
if (window.XMLHttpRequest)
9
  {// IE7+, Firefox, Chrome, Opera, Safari 代码
10
  xmlhttp=new XMLHttpRequest();
11
  }
12
else
13
  {// IE6, IE5 代码
14
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
15
  }
16
xmlhttp.onreadystatechange=cfunc;
17
xmlhttp.open("GET",url,true);
18
xmlhttp.send();
19
}
20
function myFunction()
21
{
22
loadXMLDoc("/static/example/ajax_info.txt",function()
23
  {
24
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
25
    {
26
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
27
    }
28
  });
29
}
30
</script>
31
</head>
32
<body>
33
34
<div id="myDiv"><h2>使用 AJAX 修改文本内容</h2></div>
35
<button type="button" onclick="myFunction()">修改内容</button>
36
37
</body>
38
</html>
39