导航

$.getJSON

Examples:

Example: Loads the four most recent cat pictures from the Flickr JSONP API.

<!DOCTYPE html>
<html>
<head>
 
<style>img{ height:100px;float: left;}</style>
 
<scriptsrc="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
 
<divid="images">

</div>
<script>
$
.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",
 
{
    tags
:"mount rainier",
    tagmode
:"any",
    format
:"json"
 
},
 
function(data){
    $
.each(data.items,function(i,item){
      $
("<img/>").attr("src", item.media.m).appendTo("#images");
     
if( i ==3)returnfalse;
   
});
 
});</script>

</body>
</html>

Demo:

Example: Load the JSON data from test.js and access a name from the returned JSON data.

$.getJSON("test.js",function(json){
   alert
("JSON Data: "+ json.users[3].name);
 
});

Example: Load the JSON data from test.js, passing along additional data, and access a name from the returned JSON data.

$.getJSON("test.js",{ name:"John", time:"2pm"},function(json){
    alert
("JSON Data: "+ json.users[3].name);
   
});

posted on 2012-11-08 13:48  luluNo1  阅读(225)  评论(0)    收藏  举报