The code in ASPX
<%@ Page language="C #"autoeventwireup="true"codefile="Default.aspx.cs"inherits="_default"%><! DOCTYPE html>"http://www.w3.org/1999/xhtml">"Server"><meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/> <title></title> <style type="Text/css">#Password1 {height:15px; } #Text1 {height:15px; } </style>"Form1"runat="Server"> <div>User name: <input id="Text1"Type="text"/><asp:label id="Label1"runat="Server"text=""></asp:Label> <br/>Password: <input id="Password1"Type="Password"/><br/> <br/> <input id="Button1"Type="Button"Value="Button"/><br/> </div> </form></body>"Jquery-1.11.2.min.js"Type="Text/javascript"></script><script>//when the page is ready, then the function is triggered.$ (document). Ready (function () {$ ("#Text1"). blur (function () {//gets the value of the text box and triggers the blur focus away event, transmits the value with Ajax, accepts it, and then changes the style by value varTXT = $ ( This). Val ();//get the value of a text box//get the value and send it out with Ajax$.ajax ({//one way of AjaxUrl:"default2.aspx",//the address to sendType"POST",//the way to sendData: {Uid:txt},//the value to pass. Equivalent to default2.aspx? Uid=txt, the value must be passed through data. Value of QueryString value//start accepting return dataDataType"XML",//Accept the return value type, in XML formatSuccess:function (data)//executes the callback function, data is the returned { //var a = $ (data). Find ("Count"). Val (); //find the count tag from data and get to his text. This method is not available, use the following method varA =$ (data). text (); varB = $ ("#Label1"); if(parseint (a) = =5) {B.text ("user name can be used"); //$ ("#Label1"). HTML ("User name can be used"); } Else{B.text="user name cannot be used"; } } }); }); });</script>
The code in Axpx.cs.
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls; Public Partial classdefault2:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) { stringUID = request["UID"]. ToString (); intCount =5; //query validation can be performed after obtaining the value of the UID//using XML to pass values back to Aajx,xml is a pair of tagsResponse.Write ("<?xml version= ' 1.0 '?>");//format of XMLResponse.Write ("<count>"+count. ToString () +"</count>");//so the code goes back, there's success in the data .Response.End ();//turn off after output }}
Ajax values, ajax:asynchoronous Javascript and XML (asynchronous JS and XML). Asynchronous flush, asynchronous delivery. Submits the data for the delegate, and the callback function processes the returned data