Jquery Ajax Learning Instance sends a request to the page, returns the XML format data _jquery

Source: Internet
Author: User
First, ajaxsample.aspx

Process business data, generate XML data for jqueryrequest.aspx invocation, code as follows:
Copy Code code as follows:

protected void Page_Load (object sender, EventArgs e)
{
String uid = request.querystring["username"];
string pwd = request.querystring["password"];

Response.ContentType = "Application/xml";
Response.Charset = "Utf-8";

Response.Write ("<?xml version= ' 1.0 ' encoding= ' utf-8 '?> ')";
Response.Write (@ "<comments>");
Response.Write (@ "<comment username=" + uid + "' password= '" + pwd + "' >");
Response.Write (@ "<content> Shanghai Xuhui </content>");
Response.Write (@ "</comment>");
Response.Write (@ "</comments>");

Response.End ();
}

Second, jqueryrequest.aspx

Request ajaxsample.aspx by clicking on the button to get the XML data. The code is as follows:

Copy Code code as follows:

<title></title>
<script type= "Text/javascript" src= "Js/jquery-1.3.2.js" ></script>
<body>
<form id= "Form1" runat= "Server" >
<div id= "Fdiv" >
<input type= "text" id= "Text1"/><br/>
<input type= "text" id= "Text2"/><br/>
</div>
<div>
<div id= "Result" >div1div1div1</div>
<input type= "button" onclick= "Btnclick ()"/>
</div>
<div>
<script type= "Text/javascript" >
$ (document). Ready (
function Btnclick () {
var uid = $ ("#Text1"). Val ();
var pwd = $ ("#Text2"). Val ();
$.ajax ({
URL: "Ajaxsample.aspx",
Type: "Get",
DataType: "XML",
Data: {username:uid, password:pwd},
Success:function (data, status) {
var u = $ (data). Find ("comment"). attr ("username");
var p = $ (data). Find ("comment"). attr ("password");
var a = $ (data). Find ("comment content"). text ();
var info = "User:" + U + "Password:" + p + "address is:" + A;
$ ("#result"). HTML (info);
}
});
}//);
</script>
</div>
</form>
</body>
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.