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.