Ajax. Net asynchronous call

Source: Internet
Author: User
When a project encounters a call to the controlled end, it may sometimes experience network latency. Using ajax.net asynchronous call can improve user experience .....

In fact, the principle is very simple... can be divided:
1. server side:
1) Register Ajax.
Add
<Httphandlers>
<Add verb = "post, get" Path = "ajax/*. ashx" type = "Ajax. pagehandlerfactory, Ajax"/>
</Httphandlers>
2) Add reference Ajax. DLL to the Project
3) Register ajax to the page named webform1
Ajax. Utility. registertypeforajax (typeof (webform1); // Ajax Registration
4) Add the Ajax Method to the page
[Ajaxmethod]
Public String returna ()
{
Thread. Sleep (10000); // for more explicit asynchronous call
Return "Hello World ";
}
2. Client:
1) Add a JS script
<Script language = "JavaScript" type = "text/JavaScript">
Function ()
{
Document. getelementbyid ("label1"). innerhtml = "load .....";
Webform1.returna (B );
}
Function B (RES)
{
Document. getelementbyid ("label1"). innerhtml = res. value;
}
</SCRIPT>
2) place a server control named label1 label on the page.
<Asp: Label id = "label1" runat = "server"> </ASP: Label> <SCRIPT> A (); </SCRIPT>

Related Article

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.