Standard Method for passing parameters (jquery. Ajax)

Source: Internet
Author: User

Front-end
CopyCode The Code is as follows: <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> No title page </title>
<SCRIPT type = "text/JavaScript" src = "jquery/jquery-1.2.6.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
// This method encapsulates the Ajax Method for convenient calling.
Function myajax (){
// Use this method to transmit data
VaR arr = {
"Name": "Tree ",
"ID": "123"
};
$. Get (
"Ajax. aspx ",
Arr,
Callback,
"JSON"
);
}
// Callback function
Function callback (data ){
$ ('# Response'). append (data. Name + data. ID );
Certificate ('{wait'}.css ("display", "NONE ");
}
// Onload () event
$ (Function (){
$ ('# Confirm'). Click (myajax );
})
// Encapsulate JSON data. This method does not work for code clarity.
/* It seems that the array format is incorrect.
VaR datastr = jsondata ();
Alert (datastr );
*/
Function jsondata (){
VaR jsonstr = "";
Jsonstr + = "\" Name \":";
Jsonstr + = "\" tree \"";
Jsonstr + = ",";
Jsonstr + = "\" ID \":";
Jsonstr + = "\" 123 \"";
Jsonstr + = "}";
Return jsonstr;
}
</SCRIPT>
</Head>
<Body>
<Div id = "Confirm"> click </div>
<Div id = "response"> receive background data </div>
<Div id = "wait" class = "hide"> Hello </div>
</Body>
</Html>

Background
Copy codeThe Code is as follows: public partial class Ajax: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
// Response. Write ("hello" + request ["name"]);
Hashtable ht = new hashtable ();
Ht. Add ("name", request. Params ["name"]);
Ht. Add ("ID", request. Params ["ID"]);
Response. Write (createjsonparams (HT ));
Response. End ();
}
Private string createjsonparams (hashtable items)
{
String returnstr = "";
Foreach (dictionaryentry item in items)
{
Returnstr + = "\" "+ item. Key. tostring () +" \ ": \" "+ item. value. tostring () + "\",";
}
Return "{" + returnstr. substring (0, returnstr. Length-1) + "}";
}
}

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.