Use Ajax Pro

Source: Internet
Author: User

Recently I read about ajax pro, because this method is used when WebPhone is to be developed,

WebpHone is a page that can be used to go to MakeCall on the Web. The process is to provide a method for MakeCall to be sent to the Agent or to the user through automatic dialing when the user wants to contact the customer, connect to the Agent after connection. of course, this requires hardware support.

Here I will just talk about a method to call the background at the front end. The Ajax Pro method is used. As for the background processing process, it is too troublesome to skip it.

1. Introduce ajax. dll into the project.

2. Modify the Web. config file and add the following content to the System. web node:

<HttpHandlers>
<Add verb = "POST, GET" path = "ajax/*. ashx" type = "Ajax. PageHandlerFactory, Ajax"/>
</HttpHandlers>

3. Add Ajax support in the Page_Load method of the page to be used. And write a simple method, and mark the attribute of the method as AjaxMethod.

Public partial class Demo: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{

Ajax. Utility. RegisterTypeForAjax (typeof (Demo ));
}

[Ajax. AjaxMethod (Ajax. HttpSessionStateRequirement. Read)]
Public int LogIn (string userName, string Pwd)
{
Return 0;
}
}

4. page call, where Login_CallBack is the callback method. Of course, the asynchronous method is used here. You can also use the synchronous method, as long as the synchronous party calls LogIn, do not include callback. If the call process is long, you should use an asynchronous method. After the call, you can display a loading and wait for the return. After the result is returned, go to the Update page.

Function IMG1_onclick (){
Var userName = $ ("Username"). value;
Var userpwd = $ ("Password"). value;
Demo. LogIn (userName, userpwd, Login_CallBack );
}

Function Login_CallBack (response)
{
If (response. error! = Null)
{
Alert (response. error );
Return;
}
Var states = response. value;
If (states = null)
{
Return;
}
If (states = 0)
{
Window. location = "Default. aspx ";
}
}

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.