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>