舜岳 2011-06-27
代码如下:
<!DOCTYPE html PUBLIC "-//W//DTD XHTML Transitional//EN" "http://www.worg/TR/xhtmlDTD/xhtmltransitional.dtd"> <html xmlns="http://www.worg/xhtml" > <head> <title>Test Jsonp</title> <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"></script> <script type="text/javascript"> function jsonpCallback(result) { $.each(result.items, function(i,item){ $("<img/>").attr("src", item.media.m).appendTo("body"); if ( i == 3 ) return false; }); } </script> </head> <body> <script type="text/javascript" src="http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=jsonpCallback"></script> </body> </html>
代码如下:
<!DOCTYPE html PUBLIC "-//W//DTD XHTML Transitional//EN" "http://www.worg/TR/xhtmlDTD/xhtmltransitional.dtd"> <html xmlns="http://www.worg/xhtml" > <head> <title>Test Jsonp</title> <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { $.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("body"); if (i == 3) return false; }); }); }); </script> </head> <body></body> </html>