Directory (updated articles will be connected, and an article will be updated every two to three days starting from March 13, July 25 ):
ASP. NET + jquery. Ajax details 1-opening section (published on February 25)
ASP. NET + jquery. Ajax details 2-$. Load (published on 2012.07.26)
ASP. NET + jquery. Ajax details 3-$. Get and $. Post (published on February 30)
ASP. NET + jquery. Ajax details 4-$. getjson (published on February 31)
ASP. NET + jquery. Ajax details 5-$. getscript (2012.08.04)
ASP. NET + jquery. Ajax details 6-$. ajaxsetup (2012.08.06)
ASP. NET + jquery. Ajax details 7-Global Ajax events (published on 2012.08.09)
ASP. NET + jquery. Ajax details 8-core $. Ajax (published on February 12)
ASP. NET + jquery. Ajax details 9-serialize and serializearray (February 15)
ASP. NET + jquery. Ajax detailed description: 10-json and XML + are written at the end of the article (published on February 20 !)
Jquery. getjson (URL, [data], [callback])
Load JSON data using http get requests.
Parameters
URL: the requested URL.
Data: Key/value parameter to be sent.
Callback: callback function when the load is successful.
Jquery. getjson provides the callback function, which has three parameters: responsetext, textstatus, and XMLHttpRequest, which respectively represent the content, Request status, and XMLHttpRequest objects returned by the request.
$. Get ("Data/getserviceinfo. aspx ", function (responsetext, textstatus, XMLHttpRequest) {// responsetext: Content returned by the request // textstatus: Request status: Success, error, notmodified, timeout // XMLHttpRequest: XMLHTTPRequest object });
Instance (vs2010 ):
Client --
<% @ Page Language = "C #" autoeventwireup = "true" codebehind = "jqueryajaxgetjson. aspx. cs" inherits = "jqueryajaxtest. jqueryajaxgetjson" %> <! 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">
Server --
Using system; using system. collections. generic; using system. LINQ; using system. web; using system. web. ui; using system. web. UI. webcontrols; namespace jqueryajaxtest. data {public partial class getcity: system. web. UI. page {private string resulttype = "JSON"; protected void page_load (Object sender, eventargs e) {// obtain the request parameter if (! String. isnullorempty (request. querystring ["resulttype"]) {resulttype = request. querystring ["resulttype"]. tolower () = "html "? "Html": "JSON";} string html = getresult (resulttype); // clear the Buffer Response. clear (); // write the string to the response output stream response. write (HTML); // send the Current Buffer output to the client, and stop this page to execute response. end ();} private string getresult (string resulttype) {string result = ""; if (resulttype = "html ") {// returned HTML result = @ "<ul> <li id =" 1 ""> Beijing </LI> <li id = "2" "> Tianjin </ LI> </ul> ";} else if (resulttype = "JSON") {// returned JSON data result = @ "[{" "pkid" ":" "0001" "," "provinceid "": "" BJ "", "" cityname ":" "Beijing" "," "citynameen": "" Beijing "", "" postcode "": "" 010 "", "" ishotcity "": false}, {"" pkid "": "0002" "," "provinceid" ":" TJ "", "" cityname ":" "Tianjin" "," "citynameen" ":" "Tianjin" "," "postcode" ":" 022 "", "" ishotcity "": false}] ";}return result ;}}}
What is JSON? What is the difference with XML?
Although XML has been widely used in many applications, it is not perfect. Especially in Ajax applications, XMLHttpRequest checks the MIME type of the returned data, XMLHttpRequest runs XML parser to parse the returned documents and build the corresponding DOM tree in the memory. Then, you can use the standard DOM method of JavaScript to operate the DOM tree. As we all know, Dom is not an efficient method. Another problem is that if you want to use JavaScript objects instead of XML data directly, you have to traverse the entire DOM tree to create the corresponding objects.
JSON is displayed in front of us.
JSON provides a standard data exchange format that is more suitable for Ajax applications. JSON (JavaScript Object Notation) is a lightweight data exchange format. Easy to read and write. It is also easy to parse and generate machines.
For more information, see ASP. NET + jquery. Ajax for details about 10-json and XML.