Jquery Ajax instance: send a request to the page to return XML format data

Source: Internet
Author: User

I. AjaxSample. aspx

Process business data and generate XML data for JqueryRequest. aspx to call. The Code is 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> Xuhui District, Shanghai </content> ");
Response. Write (@ "</comment> ");
Response. Write (@ "</comments> ");

Response. End ();
}

Ii. JqueryRequest. aspx

Click the button to request AjaxSample. aspx to obtain XMl data. The Code is as follows:

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Jquery Ajax instance: XML format data is returned when a request is sent to the page-Liehuo.net </title>
<Script type = "text/javascript" src = http://www.bkjia.com/uploads/Common/jquery-1.3.2.min.js> </script>
</Head>
<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 + "The address is:" +;
$ ("# Result" pai.html (info );
}
});
}//);

</Script>
</Div>
</Form>
</Body>
</Html>

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.