XMLHttpRequest

源码下载地址:http://download.csdn.net/source/782646 

静态页面

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4.     <title>Ajax获取数据过程</title>
  5.     <script language="javascript" type="text/javascript">
  6.      var xmlHttp;
  7.      /*****创建XMLHttpRequest*****
  8.       如果是ie则执行第一个.
  9.       ******************/
  10.      function createXMLHttpRequest(){
  11.         if(window.ActiveXObject)
  12.             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  13.         else if(window.XMLHttpRequest)
  14.             xmlHttp=new XMLHttpRequest();
  15.      }
  16.      /*****执行异步调用*****
  17.       open();多个重载:
  18.         参数一,GET或POST
  19.         参数二,url路径
  20.         参数三,异步标志,true即异步
  21.         参数四,五,用户名,密码
  22.       onreadystatechange属性设置回调函数
  23.       send()发送open()方法建立的请求.
  24.         有可选参数.可为空.
  25.       ******************/
  26.      function startRequest(){
  27.         createXMLHttpRequest();
  28.         xmlHttp.open("GET","AjaxServe.aspx?firstName=treebirthday=1981-03-21",true);
  29.         xmlHttp.onreadystatechange=callback_state;//用函数名,不加括号.
  30.         xmlHttp.send(null);
  31.      }
  32.      /*****回调函数*****
  33.       xmlHttp.responseText;//取得返回数据
  34.       readyState,对象的状态:
  35.         0,未初始化
  36.         1,正在装载
  37.         2,装载完毕
  38.         3,交互
  39.         4,完成
  40.       status,服务器请求HTTP状态代码的数字代码
  41.       ******************/
  42.      function callback_state(){
  43.         if(xmlHttp.readyState==4 && xmlHttp.status==200)
  44.             document.getElementById("target").innerHTML+=xmlHttp.responseText;
  45.             //document.write(xmlHttp.responseText);
  46.      }
  47.     </script>
  48. </head>
  49. <body>
  50. <input type="button" value="测试" onclick="startRequest()" />
  51. <br /><br />
  52. <div id="target">目标:<br /></div>
  53. </body>
  54. </html>

动态页面

  1.     protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         if (Request.HttpMethod == "POST")
  4.         {
  5.             Response.Write("POST:" + Request["firstName"] + ",your birthday is" + Request["birthday"]);
  6.             Response.End();
  7.         }
  8.         else if (Request.HttpMethod == "GET")
  9.         {
  10.             Response.Write("GET:" + Request["firstName"] + ",your birthday is" + Request["birthday"]);
  11.             Response.Write("<br/>");
  12.             //Response.Write("<script>alert('Hello');</script>");
  13.             Response.End();
  14.         }
  15.     }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值