I. ajaxsample. aspx
Process business data and generate XML data for jqueryrequest. aspx to call,CodeAs 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 code The 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>