实例入门(ajax)

 静态页面

  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>无标题页</title>
  5.     <script type="text/javascript" src="jquery/jquery.js" >
  6.         //这里不可以用<script type="" src="" />
  7.     </script>
  8.     <script type="text/javascript">
  9.     /*
  10.       encodeURI 方法
  11.       对URL传递的参数进行编码
  12.       将文本字符串编码为一个有效的统一资源标识符 (URI)。
  13.     */
  14.      function createQueryString(){
  15.         var firstName=encodeURI($("#firstName").val());
  16.         var birthday=encodeURI($("#birthday").val());
  17.         //组合成对象的形式
  18.         var queryString={firstName:firstName,birthday:birthday};
  19.         return queryString;
  20.      }
  21.      function doRequestUsingGET(){
  22.         $.get("AjaxServe.aspx",createQueryString(),
  23.             //发送GET请求
  24.             function(data){
  25.                 $("#serverResponse").html(decodeURI(data));
  26.             }
  27.          );
  28.      }
  29.      function doRequestUsingPOST(){
  30.         $.post("AjaxServe.aspx",createQueryString(),
  31.             //发送POST请求
  32.             function(data){
  33.                 $("#serverResponse").html(decodeURI(data));
  34.             }
  35.          );
  36.      }
  37.     </script>
  38. </head>
  39. <body>
  40.  <h2>输入姓名和生日</h2>
  41.  <form>
  42.   <input type="text" id="firstName" /><br />
  43.   <input type="text" id="birthday" />
  44.   
  45.   <input type="button" value="GET" onclick="doRequestUsingGET();" /><br />
  46.   <input type="button" value="POST" onclick="doRequestUsingPOST();" />
  47.  </form>
  48.  <div id="serverResponse"></div>
  49. </body>
  50. </html>

动态页面

  1.     protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         //Response.Write("后台数据");
  4.         if (Request.HttpMethod == "POST")
  5.             Response.Write("POST:" + Request["firstName"] + ",your birthday is" + Request["birthday"]);
  6.         else if(Request.HttpMethod=="GET")
  7.             Response.Write("GET:" + Request["firstName"] + ",your birthday is" + Request["birthday"]);
  8.     }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值