zoukankan      html  css  js  c++  java
  • 前台调用后台事件的方法

    前台:

    <html>
    <head id="Head1" runat="server">
      <meta http-equiv="content-type" content="text/html;charset=gb2312" />
      <script src="../../js/jquery-1.3.2.js" type="text/javascript"></script>
    </head>
    <body>
    <input type="button" value="调用Test" onclick="CallMethod('Test')"/><input type="button" value="调用Test1" 

    onclick="CallMethod('Test1')"/><input type="button" value="调用Test2" onclick="CallMethod('Test2')"/>
    <script type="text/javascript">
        function CallMethod(method){
            $.ajax(
      {
          type: "POST",
          url: "WebForm1.aspx",
          data: { method: method },
          success: function(msg) { alert(msg); },
          error: function() { alert('出错了'); }
      }
      )
        }

    </script>
    </body>
    </html>

    后台:

     protected void Page_Load(object sender, EventArgs e)
            {
                Response.Charset = "gb2312";
                if (Request.Form["method"] == "Test") Test();
                else if (Request.Form["method"] == "Test1") Test1();
                else if (Request.Form["method"] == "Test2") Test2();

                Response.Write("一般请求<br/>");


            }


            [System.Web.Services.WebMethod]
            public static string SayHello()
            {
                return "Hello Ajax!";
            }


            public void Test()
            {
                Response.Write("执行Test方法" + DateTime.Now);
                Response.End();//停止其他输出
            }
            public void Test1()
            {
                Response.Write("执行Test1方法" + DateTime.Now);
                Response.End();//停止其他输出
            }
            public void Test2()
            {
                Response.Write("执行Test2方法" + DateTime.Now);
                Response.End();//停止其他输出
            } 

  • 相关阅读:
    phpexcel导出带生成图片完美案例
    让Asp.Net WebAPI支持OData查询,排序,过滤。(转)
    Workflow笔记2——状态机工作流(转)
    WebAPI请求(转)
    WebApi参数传递总结(转)
    30分钟搞定后台登录界面(103个后台PSD源文件、素材网站)(转)
    .net 分布式架构之分布式锁实现(转)
    C#分布式事务解决方案-TransactionScope(转)
    Windows 环境下分布式跨域Session共享(转)
    Session分布式共享 = Session + Redis + Nginx(转)
  • 原文地址:https://www.cnblogs.com/tongdengquan/p/6090582.html
Copyright © 2011-2022 走看看