Achieve partial refresh of web pages

Source: Internet
Author: User

The server's return will trigger the whole page refresh. How can we just refresh the part? I saw a usage in the book a few days ago.
WebService behavior. I tried it today. The effect is good.
In the web directory, a file webservice. htc is required.
Here you can download: http://msdn.microsoft.com/workshop/author/webservice/webservice.htc
See a WebService file named Service1.asmx:
[WebService (Namespace = "http: // localhost/BehaviorService/")]
Public class TestService: System. Web. Services. WebService
{
/// <Summary>
/// Return the server time
/// </Summary>
[WebMethod]
Public string GetServerTime ()
{
Return DateTime. Now. ToString ();
}
}
Enter an html file in the directory of the same level with the following content:
<Script>
Var intCallId = 0;
Function Init ()
{
GetServerTime ();
SetInterval ("GetServerTime ()", 1000 );
}
Function GetServerTime ()
{
Service. useService ("Service1.asmx? WSDL "," TestService ");
IntCallId = Service. TestService. callService ("GetServerTime ");
}
Function service_result ()
{
If (event. result. error)
{
Showresult. innerText = event. result. errorDetail. string;
}
Else
{
Showresult. innerText = event. result. value;
}
}
</Script>
<Html>
<Body onload = "Init ();">
<Div id = "Service" style = "behavior: url (webservice. htc)" onresult = "service_result ()"> </div>
<Span id = showresult> </span>
</Body>
</Html>
Check http: // localhost/BehaviorService/test1.htm to see the time on a server.
This method can be used to partially refresh the page.
There are two restrictions:
1. The behavior can only be performed using the web service in the domain, because of the built-in security restrictions of DHTML
2. Access types in this way will be restricted, and the behavior supports the basic. net types and their arrays.
For example, dataset and datatable are not supported for complex types.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.