Hasan Alaca
Hasan Alaca

Reputation: 232

I can get id and date but not the image url from Tumblr API

I can get the id and date but not the photo itself from tumblr json api :(

http://jsfiddle.net/82wNq/11/

$.getJSON("http://fuckyeahgirlswithvinylrecords.tumblr.com/api/read/json?callback=?", function (data) {
    $.each(data.posts, function (index, item) {
        $("<div>").html(item.id).appendTo("#content");
        $("<div>").html(item.date).appendTo("#content");
        $("<img>").attr("src", item.photo-url-100).appendTo("#content");
    });
});

Upvotes: 0

Views: 255

Answers (3)

melc
melc

Reputation: 11671

Call it as follows,

$.getJSON("http://fuckyeahgirlswithvinylrecords.tumblr.com/api/read/json?callback=?", function (data) {
    $.each(data.posts, function (index, item) {
        $("<div>").html(item.id).appendTo("#content");
        $("<div>").html(item.date).appendTo("#content");
        $("<img>").attr("src", item['photo-url-100']).appendTo("#content");
    });
});

Upvotes: 1

zzlalani
zzlalani

Reputation: 24374

change item.photo-url-100 to item['photo-url-100']

Upvotes: 1

Jason P
Jason P

Reputation: 27012

Properties can't have dashes in them. Use bracket notation:

http://jsfiddle.net/ZFZ6R/

$("<img>").attr("src", item['photo-url-100']).appendTo("#content");

Upvotes: 3

Related Questions