• AJAX获取服务器当前时间


    ------------------------------ WebService1.asmx----------------------------------

    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。

        [System.Web.Script.Services.ScriptService]
        public class WebService1 : System.Web.Services.WebService
        {
            [WebMethod]
            public string HelloWorld()
            {
                return "Hello World";
            }
        
            [WebMethod]
            public string GetDate()
            {
                return DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            }

        }

    ------------------------------------HTMLPage1.htm---------------------------------------

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
         <script src="js/Jquery1.7.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
               function GetDate() {
                   $.ajax({
                       type: "post", //客户端向服务器发送请求时采取的方式
                       contentType: "application/json", //指定客户端发送给服务器的内容的类型以及服务器返回给客户端内容的类型为json格式
                      url: "WebService1.asmx/GetDate", //指明客户端要向哪个页面里面的哪个方法发送请求
                       data: "{}", //指定伴随发送的请求传递到服务器的参数
                       success: function (result) {//客户端调用服务器端方法成功后执行的回调函数。
                          $('#mydiv').text(result.d);
                       }
                  })
              }
                setInterval(GetDate, 1000);
            })
        </script>
    </head>
    <body>
    <div id="mydiv"></div>
        <input id="Button1" type="button" value="获取服务器时间" />
    </body>
    </html>


  • 相关阅读:
    UPC2018组队训练赛第二场
    杭电多校训练第十场
    socks5 代理
    windows pip 报错Unable to find vcvarsall.bat
    emacs笔记
    homestead oci8
    pyenv install
    chrome 设置sock5代理
    laravel 接收post json
    laravel 使用已有数据库自动创建model
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3089202.html
Copyright © 2020-2023  润新知