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

Source: Internet
Author: User

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:&nbsp;&nbsp;&nbsp; <input id="Text1"Type="text"/><asp:label id="Label1"runat="Server"text=""></asp:Label> <br/>Password:&nbsp; &nbsp;&nbsp; <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

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.