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();//停止其他输出
            } 

  • 相关阅读:
    解决Chrome关联HTML文件,图标不显示的问题。
    Tomcat启动超时问题Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds
    matlalb 的后台运行方式
    新转移注意(caffe):ImportError: libcudart.so.7.0: cannot open shared object file: No such file or directory
    查看nvidia显卡命令
    train validation test
    lmdb数据格式
    github
    2016 hosts
    opencv3.0 imread问题
  • 原文地址:https://www.cnblogs.com/tongdengquan/p/6090582.html
Copyright © 2011-2022 走看看