I. ajaxjson. aspx
Process business data and generate JSON data for jqueryrequest. aspx to call,
Code As follows:
Copy code The 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 code The 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>