Home > Article > Web Front-end > jQuery.getJSON(url, [data], [callback]) Basic introduction
Load JSON data via HTTP GET request.
In jQuery 1.2, you can load JSON data from other domains by using the callback function in JSONP form, such as "myurl?callback=?". jQuery will automatically replace ? with the correct function name to execute the callback function. Note: The code after this line will be executed before this callback function is executed.
Sending request address.
Key/value parameters to be sent.
Callback function when loading is successful.
Load 4 latest pictures of cats from the Flickr JSONP API.
<p id="images"></p>
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?", function(data){ $.each(data.items, function(i,item){ $("<img/>").attr("src", item.media.m).appendTo("#images"); if ( i == 3 ) return false; }); });
Load JSON data from test.js and display a name field in the JSON data data.
$.getJSON("test.js", function(json){ alert("JSON Data: " + json.users[3].name); });
Load JSON data from test.js, append parameters, and display a name field data in the JSON data.
$.getJSON("test.js", { name: "John", time: "2pm" }, function(json){ alert("JSON Data: " + json.users[3].name); });
This article was written by the author: Chen Xizhang on 2009/7/2 8:27:43
Published at: http://www.cnblogs.com/chenxizhang/
The copyright of this article belongs to the author and can be reproduced. However, this statement must be retained without the author's consent, and a link to the original text must be provided in an obvious position on the article page, otherwise We reserve the right to pursue legal liability.
For more blog posts, as well as the author’s complete statement on blog citation and cooperation policies, please refer to the following site: Chen Xizhang’s Blog Center
The above is the detailed content of jQuery.getJSON(url, [data], [callback]) Basic introduction. For more information, please follow other related articles on the PHP Chinese website!