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.     }  
  • 相关阅读:
    vue-自定义指令
    vue-自定义过滤器--时间
    vue-jsonp
    vue-post
    vue-get-参数
    vue-get
    vue-百度下拉列表
    C#网页授权获取微信Openid
    C#微信环境分享页面给微信好友、朋友圈
    IIS服务器同时使用多个https证书如何操作443端口
  • 原文地址:https://www.cnblogs.com/momjs/p/6140892.html
Copyright © 2011-2022 走看看