I. AjaxJson. aspx
Process business data and generate JSon 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 u = Request ["UserName"];
String p = Request ["Password"];
String output = string. Format ("'username': '{0}', 'Password': '{1}'", u, p );
Response. Write ("[{");
Response. Write (output );
Response. Write ("}]");
Response. End ();
}
Ii. JqueryRequest. aspx
Click the button to request AjaxJson. aspx to obtain JSon 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" language = "javascript" src = "js/jquery-1.3.2.js"> </script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Input type = "text" name = "Text1" id = "Text1"/> <br/>
<Input type = "text" name = "Text2" id = "Text2"/>
<Br/>
<Input type = "button" id = "btn1" onclick = "BtnClick ()"/>
</Div>
<Div id = "dd">
Sd
</Div>
<Div>
<Script type = "text/javascript" language = "javascript">
Function BtnClick (){
Var uid = $ ("# Text1"). val ();
Var pwd = $ ("# Text2"). val ();
$. Ajax ({
Url: "AjaxJson. aspx ",
Type: "POST ",
Data: {UserName: uid, Password: pwd },
Success: function (data ){
Var json = eval (data); // eval ("(" + data + ")");
$. Each (json, function (idx, item ){
Var user = item. UserName;
Var pass = item. Password;
$ ("# Dd" ).html ("});
}
});
}
</Script>
</Div>
</Form>
</Body>
</Html>