First, ajaxjson.aspx
Process business data, generate JSON data for jqueryrequest.aspx invocation, code as follows:
Copy Code code 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 ();
}
Second, jqueryrequest.aspx
Request ajaxjson.aspx by clicking on the button to get the JSON data. The code is as follows:
Copy Code code as follows:
<title></title>
<script type= "Text/javascript" language= "JavaScript" src= "Js/jquery-1.3.2.js" ></script>
<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>