------------------------------ Webservice1.asmx ----------------------------------
// To allow ASP. Net ajax to call this web service from a script, cancel the comments to the downstream.
[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", // method used when the client sends a request to the server
Contenttype: "application/JSON", // specifies the type of content that the client sends to the server and the type of content that the server returns to the client in JSON format.
URL: "webservice1.asmx/getdate", // specifies the method on which the client sends the request
Data: "{}", // specify the parameters that are sent along with the request to the server
Success: function (result) {// callback function executed after the client successfully calls the server method.
$ ('# Mydiv'). Text (result. D );
}
})
}
Setinterval (getdate, 1000 );
})
</SCRIPT>
</Head>
<Body>
<Div id = "mydiv"> </div>
<Input id = "button1" type = "button" value = "Get server time"/>
</Body>
</Html>