AJAX is "A
SynchronousJ
Avascript andX
ML"(Asynchronous JavaScript and XML) is a way to create
InteractiveWeb page application of Web development technology. AJAX = Asynchronous JavaScript and XML (a subset of standard generic markup languages). AJAX is a
techniques for creating fast, Dynamic Web pages。
AJAX enables Web pages to be updated asynchronously by exchanging small amounts of data in the background with the server. This means that
You can update a part of a webpage without reloading the entire page
. Traditional Web pages (without AJAX) if you need to update the content, you must reload the entire page page. The term derives from the transformation that describes a Web-based application to a data-based application. In data-based applications, data such as user needs, such as contact lists, can be obtained from the server independent of the actual Web page and can be dynamically written to the Web page, rendering the slow Web application experience like a desktop application.
the core of AJAX is the JavaScript object XMLHttpRequest。 This object was first introduced in Internet Explorer 5, which is a technique that supports asynchronous requests. Nutshell
XMLHttpRequest allows you to use JavaScript to make requests to the server and process the response without blocking the user。 Baidu Encyclopedia: http://baike.baidu.com/item/ajax/8425first refer to jquery, then write the codeCode format:(Lee brainstorming lxc)
$.ajax ({ URL:"",// to which server to send this request to data:{},// to the data on the service side, There can be no, or multiple type:"post"// delivery mode DataType: " JSON ",/// data-passing format success:function (data) {}// If you successfully return to execute this method," data " As a custom name });
1, the General Data Processing Program (interface): Ashx file 2, cross-language transmission of data XML Extensible Markup Language structure is not clear the size of the code to find more trouble non-object-oriented structure JSON structure clear code size relatively small object-oriented processing, find the data is simple basic Structure:Key-value pairs: {"": "", "": "', " ":"}(in English) ============================================================= exercise: Verify that the user name is available in one, normal way, without the Ajax foreground code:
<body> <form id="Form1"runat="Server"> <div> <br/><br/><br/><br/><br/><br/><br/><br/> ; <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/ ><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/ ><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/ ><br/><br/><br/><br/><br/><br/><br/><br/> <asp:TextBo X id="TextBox1"runat="Server"autopostback="true"></asp:TextBox> <asp:label id="Label1"runat="Server"text="Label"></asp:Label> </div> </form></body>
Front Code
Background code:
Public Partial class_default:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) {textbox1.textchanged+=textbox1_textchanged; } voidtextBox1_TextChanged (Objectsender, EventArgs e) { if(TextBox1.Text = ="Zhangsan"|| TextBox1.Text = ="Lisi") {Label1.Text="user name already exists! "; Label1.forecolor=System.Drawing.Color.Red; } Else{Label1.Text="Congratulations! User name can be used! "; Label1.forecolor=System.Drawing.Color.Green; } }}Background Code
When the focus is lost, the event is triggered and the entire page is reloaded and the user experience is poor!
Second, Ajax local refresh
Front Code:
<body> <form id="Form1"runat="Server"> <div> <asp:textbox id="TextBox1"runat="Server"></asp:TextBox> <asp:label id="Label1"runat="Server"text="Label"></asp:Label> </div> </form></body>
Front Code
Background code:
varTxt1 = document.getElementById ("TextBox1"); Txt1.onkeyup=function () {varv =Txt1.value; $.ajax ({URL:".. /ajax/handler.ashx", data: {"txt1": v}, type:"Post", DataType:"JSON", Success:function (data) {document.getElementById ("Label1"). InnerHTML =Data.ok; if(Data.ok1 = ="true") {document.getElementById ("Label1"). Style.color ="Green"; } Else{document.getElementById ("Label1"). Style.color ="Red"; } } });};JS Code
<%@ WebHandler language="C #"class="Handler"%>usingSystem;usingsystem.web; Public classHandler:ihttphandler { Public voidProcessRequest (HttpContext context) {stringS=context. request["txt1"]; stringJSON ="{\ "ok\": \ "Congratulations! User name available! \ ", \" ok1\ ": \" true\ "}"; if(s = ="Zhangsan"|| s = ="Lisi") {JSON="{\ "ok\": \ "This user name is not available! \ ", \" ok1\ ": \" false\ "}"; } context. Response.Write (JSON); Context. Response.End (); } Public BOOLisreusable {Get { return false; } }}ashx Code
C#-webform-ajax Ajax (i) basic format