Preliminary use of AJAX

Source: Internet
Author: User

Ajax is short for "Asynchronous JavaScript + XML", that is, Asynchronous JavaScript and XML processing. In principle, AJAX can call httprequest to Implement Asynchronous Communication with the server, and finally implement a rich and friendly user interface on the webpage.
Steps for configuring Ajax
1. Copy Ajax. DLL to the bin directory of the application system and reference Ajax. dll in the project reference. If not, download/files/singw.ine/ajax.rar.
2. Configure web. config and add the following information:

< Httphandlers >
< Add Verb = "Post, get" Path = "Ajax/*. ashx" Type = "Ajax. pagehandlerfactory, Ajax"   />
</ Httphandlers >

3. Assume that the application system is called document and the Directory format is pages \ ajaxtest.
4. Create the CS file ajaxmethod. CS under pages \ ajaxtest and add the following method: // [Ajax. ajaxmethod]
[Ajax. ajaxmethod (Ajax. httpsessionstaterequirement. Read)]
Public   Static   String Getnivnumber ( String Str)
{
 ReturnSTR;
}

5. Create the page ajaxform. aspx under pages \ ajaxtest < Html >
  < Head >
< Title > Ajaxform </ Title >
< Meta Name = "Generator" Content = "Microsoft Visual Studio. net7.1" >
< Meta Name = "Code_language" Content = "C #" >
< Meta Name = "Vs_defaultclientscript" Content = "JavaScript" >
< Meta Name = "Vs_targetschema" Content = "Http://schemas.microsoft.com/intellisense/ie5" >
< Script Language = "JavaScript" >
Function Testajax ()
{
VaRFirst=Document. getelementbyid ("Txtfirst");
Ajaxmethod. getnivnumber (first. Value, callback_getnivnumber );
}
Function Callback_getnivnumber (RES)
{< br> var OBJ = document. getelementbyid ( " txtsecond " );
obj. value = res. value;
}
</ Script >
  </ Head >
  < Body Ms_positioning = "Gridlayout" >
< Form ID = "Form1" Method = "Post" Runat = "Server" >
< Input Style = "Z-INDEX: 101; left: 208px; position: absolute; top: 40px" Type = "Button" Value = "Button"
Onclick = "Testajax ();" >
< ASP: textbox ID = "Txtfirst" Style = "Z-INDEX: 102; left: 40px; position: absolute; top: 40px" Runat = "Server" > </ ASP: textbox >
< ASP: textbox ID = "Txtsecond" Style = "Z-INDEX: 103; left: 40px; position: absolute; top: 72px" Runat = "Server" > </ ASP: textbox >
</ Form >
  </ Body >
</ Html > Protected System. Web. UI. webcontrols. textbox txtfirst;
Protected System. Web. UI. webcontrols. textbox txtsecond;
Private   Void Page_load ( Object Sender, system. eventargs E)
{
 //Registration. The document. pages. ajaxtest. ajaxmethod is the namespace where the ajaxmethod. Cs method is located.
Ajax. Utility. registertypeforajax (Typeof(Document. pages. ajaxtest. ajaxmethod ));
}

Then you can run it,
Effect: Enter the content in the first textbox and click button to display the content in the second textbox. This is just a simple example. You can also modify the calling method, read data from the database, and perform more complex operations.

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.