加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

AJAX获取服务器当前时间

发布时间:2020-12-15 22:06:13 所属栏目:百科 来源:网络整理
导读:------------------------------WebService1.asmx---------------------------------- // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Se

------------------------------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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读