Sunday, June 3, 2012

Load Flickr image in JSON format, using jQuery

Example to load Flickr image in JSON format, using jQuery.

Load Flickr image in JSON format, using jQuery


<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
  <script>
  $(document).ready(function(){
  
    var div_flickrimage = document.getElementById("flickrimage");
    var new_ul = $(document.createElement("ul"));
    $(new_ul).appendTo(div_flickrimage);
  
    $.getJSON(
      "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",
      { format: "json"},
        function(data){
          $.each(data.items, function(i,item){
          
            var new_li = $(document.createElement("li"));
            $("<img/>").attr("src", item.media.m).appendTo(new_li);
            new_li.appendTo(new_ul);
            
          });          
        }
      );
  })  

  </script>
</head>
<body>
  <div id="flickrimage"></div>

</body>
</html>


Related:
- Load Flickr images and display in horizontal scroll bar, using jQuery.


No comments:

Post a Comment