Jquery Ajax Learning Instance 2 sending a request to a page returns JSON format data _jquery

Source: Internet
Author: User
Tags eval
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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.