I am also a newbie. After a long time, I finally wrote my first Ajax instance and shared it. I hope other friends can quickly write their first Ajax instance.Program!
Ajax, short for Asynchronous JavaScript and XML, is Asynchronous JavaScript and XML. Ajax is not a new technology, but a comprehensive application of JavaScript, XML, XMLHttpRequest, and other technologies. The above is the official definition,In my opinion, Ajax is usedCode/Function, which is executed in Javascript mode to achieve the technology of not refreshing the interface. (Purely personal opinion. Welcome to shoot bricks)
Let's get down to the truth. Next we will introduce my first Ajax program:
Program Description: If the interface is not refreshed, click the button to display the server time.
1. Preparation: Download A. Net Ajax Development Kit to get twice the result with half the effort. For more information, see the http://ajax.schwarz-interactive.de. It is a DLL. the version I used is 5.7.25.1, the development environment is vs2005, and the operating system is Vista (UAC disabled ).
2. Create an Asp.net project and add configuration information to Web. config.
1 < System. Web >
2 < Httphandlers >
3 < Add verb = " Post, get " Path = " Ajax/*. ashx " Type = " Ajax. pagehandlerfactory, Ajax " />
4 </ Httphandlers >
5 </ System. Web >
3. In this Asp.net project, add a pair to create an Asp.net project. (Or copy the file directly to the bin directory)
4. Create a page named mypage. aspx.
Its aspx code: 1 <% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Mypage. aspx. CS " Inherits = " Mypage " %>
2
3 <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
4 < Html Xmlns = "Http://www.w3.org/1999/xhtml" >
5 < Head Runat = "Server" >
6 < Title > Untitled page </ Title >
7 </ Head >
8 < Body >
9 < Form ID = "Form1" Runat = "Server" >
10 < Div >
11 < Input Type = "Button" Value = "Click here to get datetime" Onclick = "Javascript: doit ()" />
12 < BR />
13 < BR />
14 < Textarea ID = "Textarea1" Name = "Mydisplay" Rows = "2" Style = "Width: 506px" Cols = "2" > </ Textarea >
15 </ Div >
16 </ Form >
17
18 < Script Language = "JavaScript" >
19 Function Doit ()
20 {
21Document. Forms [0]. Mydisplay. Value=Mypage. getstring (). value;
22}
23 </ Script >
24
25 </ Body >
26 </ Html >
27
Its CS code 1 Using System;
2 Using System. Data;
3 Using System. configuration;
4 Using System. collections;
5 Using System. Web;
6 Using System. Web. Security;
7 Using System. Web. UI;
8 Using System. Web. UI. webcontrols;
9 Using System. Web. UI. webcontrols. webparts;
10 Using System. Web. UI. htmlcontrols;
11
12 Public Partial Class Mypage: system. Web. UI. Page
13 {
14 Protected Void Page_load ( Object Sender, eventargs E)
15 {
16Ajax. Utility. registertypeforajax (Typeof(Mypage ));
17}
18
19 [Ajax. ajaxmethod]
20 Public String Getstring ()
21 {
22Datetime d=Datetime. now;
23Return "The time is" +D. tostring ();
24}
25 }
26
5. Run and click the button to display the server time without refreshing the interface.