How to extract url data from Reddit API using JSON

前端 未结 1 1719
无人及你
无人及你 2020-12-03 02:11

I\'m trying to extract the image post URLs from a subreddit feed, and render elements on my page.

Been trying to hack together the .ge

相关标签:
1条回答
  • 2020-12-03 02:22

    You are using the wrong url. Use this:

    $.getJSON("http://www.reddit.com/r/pics/.json?jsonp=?", function(data) { 
        // Do whatever you want with it.. 
    });
    

    EDIT : Working example based on your fiddle in the comments.

    $.getJSON("http://www.reddit.com/r/pics/.json?jsonp=?", function(data) { 
        $.each(data.data.children, function(i,item){
            $("<img/>").attr("src", item.data.url).appendTo("#images");
        });
    });
    

    You should use data.data.children and not data.children

    0 讨论(0)
提交回复
热议问题