zoukankan      html  css  js  c++  java
  • 仅用aspx文件实现Ajax调用后台cs程序。(实例)

    仅用aspx文件实现Ajax调用后台cs无刷新程序。(实例)

    两个文件:aaa.aspx 和aaa.aspx.cs

    一、aaa.aspx 

    [csharp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. <script type="text/javascript">  
    2.        
    3.         function Request() {  
    4.             alert("1");  
    5.             $.ajax({  
    6.                 type: 'post',  
    7.                 url: 'Test442.aspx?method=Send2',   // 【调用后台的事件】  
    8.                 cache: false,  
    9.                 success: function (data) {  
    10.                     if (data == '00000') {  
    11.                         //receive();  
    12.                     }  
    13.                     var tbReceive = $('#tbReceive').val();  
    14.                     $('#tbReceive').val(tbReceive + data + ";");  
    15.                 },  
    16.                 error: function (XMLHttpRequest, textStatus) {  
    17.                 }  
    18.             });  
    19.         };  
    20.     </script>  


    二、aaa.aspx.cs

    [csharp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
      1. protected void Page_Load(object sender, EventArgs e)  
      2.     {  
      3.         string result = "";  
      4.         if (!IsPostBack)  
      5.         {  
      6.   
      7.             if (Request["method"] != null)  
      8.             {  
      9.                 try  
      10.                 {  
      11.                     switch (Request.QueryString["method"])  
      12.                     {  
      13.                         case "Send2":     
      14.                              
      15.                             result = Send2();   <span style="font-family: Arial, Helvetica, sans-serif;">// 【执行的事件send2】</span>  
      16.   
      17.                             break;  
      18.                     }  
      19.                 }  
      20.                 catch (Exception ex)  
      21.                 {  
      22.                     result = ex.Message;  
      23.                     LogManager.WriteLog(ex.Message);  
      24.                 }  
      25.                 Response.Clear();  
      26.                 Response.ContentType = "text/plain";  
      27.                 Response.ContentEncoding = System.Text.Encoding.UTF8;  
      28.                 Response.Write(result);  
      29.                 Response.End();  
      30.             }  
      31.   
      32.         }  
      33.     }  
  • 相关阅读:
    Java实现 蓝桥杯VIP 算法训练 校门外的树
    Java实现 蓝桥杯VIP 算法训练 统计单词个数
    Java实现 蓝桥杯VIP 算法训练 统计单词个数
    Java实现 蓝桥杯VIP 算法训练 开心的金明
    Java实现 蓝桥杯VIP 算法训练 开心的金明
    Java实现 蓝桥杯 算法训练 纪念品分组
    Java实现 蓝桥杯 算法训练 纪念品分组
    Java实现 蓝桥杯VIP 算法训练 校门外的树
    Java实现 蓝桥杯VIP 算法训练 统计单词个数
    Java实现 蓝桥杯VIP 算法训练 开心的金明
  • 原文地址:https://www.cnblogs.com/momjs/p/6140892.html
Copyright © 2011-2022 走看看