开发者

Print entire feed with json?

开发者 https://www.devze.com 2023-03-02 15:27 出处:网络
Im working with the code below from here: http://api.jquery.com/jQuery.getJSON/ $.getJSON(\"http://api.flickr.c开发者_JAVA技巧om/services/feeds/photos_public.gne?jsoncallback=?\",

Im working with the code below from here: http://api.jquery.com/jQuery.getJSON/

$.getJSON("http://api.flickr.c开发者_JAVA技巧om/services/feeds/photos_public.gne?jsoncallback=?",
  {
    format: "json"
  },
  function(data) {
    $.each(data.items, function(i,item){
      $("<img/>").attr("src", item.media.m).appendTo("#images");
    });
  });

How can I print out the entire feed. The following prints nothing:

$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",
  {
    format: "json"
  },
  function(data) {
    $.each(data.items, function(i,item){
      $("content").html(data);
    });
  });

On my page I have 2 divs, one with and ID of images and the other with an ID of content. Thanks

UPDATE - Ive fixed the missing hash but the first example still works but the 2nd does not.

http://smartpeopletalkfast.co.uk/json/1.html

http://smartpeopletalkfast.co.uk/json/2.html

I need to change the feed to a youtube one so I thought printing the entire contence as the simplest start to this. Thanks


See this blog post it shows how to get images from flickr api using jquery getJson


The second block of code is replacing the html of content on every loop and appears to be missing a hash or period in the selector. I imagine something along the lines of -

$("#content").append(data);  

...would do the trick. That being said, if you are just trying to view the JSON being returned why not just use chrome developer tools or firebug?


This will help:

function(data) {
    $.each(data.items, function(i,item){
      $("#content").append(item);
    });
  });
0

精彩评论

暂无评论...
验证码 换一张
取 消