码迷,mamicode.com
首页 > 编程语言 > 详细

javascript写的ajax请求

时间:2015-11-12 23:17:38      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:

 1 <html xmlns="http://www.w3.org/1999/xhtml">
 2 <head runat="server">
 3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 4     <title></title>
 5     <script type="text/javascript">
 6         onload = function () {
 7             window.document.getElementById("Button1").onclick = function () {
 8                 var xhr = null
 9                 if (XMLHttpRequest) {
10                     xhr = new XMLHttpRequest();
11                 } else {
12                     xhr = new ActiveXObject("Microsoft.XMLHTTP");//兼容IE6,IE5
13                 }
14                 xhr.open("get", "Handler2.ashx?a=bbb",true);
15                 xhr.send();
16                 xhr.onreadystatechange = function () {//回调函数
17                     if(xhr.readyState==4){
18                         if (xhr.status == 200) {
19                             alert(xhr.responseText);
20                         }
21                     }
22                 };
23 
24             }
25             
26         };
27 
28     </script>
29 </head>
30 <body>
31     <form id="form1" runat="server">
32     <div>
33     
34         <asp:Button ID="Button1" runat="server" Text="Button" />
35     
36     </div>
37     </form>
38 </body>
39 </html>

 

javascript写的ajax请求

标签:

原文地址:http://www.cnblogs.com/chao2014/p/4960542.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!