I. AjaxSample. aspx
Process business data and generate XML data for JqueryRequest. aspx to call. The Code is as follows:
Copy codeThe 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:
Copy codeThe Code is as follows:
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<Script type = "text/javascript" src = "js/jquery-1.3.2.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>