Ajax实例

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
 2 "http://www.w3.org/TR/html4/strict.dtd">
 3 
 4 <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
 5     <head>
 6         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 7         <title>Ajax实例</title>
 8         <script type="text/javascript" src="script/jquery-1.12.2.js"></script>
 9         <meta name="author" content="Administrator" />
10         <!-- Date: 2016-04-04 -->
11     </head>
12     <body>
13         <input type="button" value="Ajax提交" onclick="Ajax();" />
14         <div id="resText"></div>
15         <script type="text/javascript">
16             function Ajax() {
17               var xmlHttpReg = null;
18               if(window.ActiveXObject){
19                   xmlHttpReg = new ActiveXObject("Microsoft.XMLHTTP");
20               }else if(window.XMLHttpRequest){
21                   xmlHttpReg = new XMLHttpRequest();
22               }
23               xmlHttpReg.open("GET","test.php",true);
24               xmlHttpReg.onreadystatechange = RequsetCallBack;
25               xmlHttpReg.send(null);
26               function RequestCallBack() {
27                 if(xmlHttpReg.readyStatus==4){
28                     if(xmlHttpReq.status==200){
29                         document.getElementById("resTest").innerHTML = xmlHttpReq.responseText;
30                     }
31                 }
32               }
33             }
34         </script>
35     </body>
36 </html>
原文地址:https://www.cnblogs.com/Arther-J/p/5352026.html