Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialgeorgeprofenza
10,914 PointsError using a custom function name for the callback
If I use the displayPhoto function as the video suggests I get this error:
Uncaught ReferenceError: jsonFlickrFeed is not definedphotos_public.gne?format=jsoncallback=jQuery111206818820328917354_1429472370664&tags=Dog&format=jso…:1 (anonymous function)
Here's my code so far, with a few tweaks based on the JQuery basics course:
function displayPhoto(data){
var $photos = $('<ul>');
$.each(data.items,function(i,photo){
var $li = $('<li class="grid-25 tabled-grid-50">');
var $a = $('<a href="'+photo.link+'" class="image">');
var $img = $('<img src="'+photo.media.m+'" >');
$a.append($img);
$li.append($a);
$photos.append($li);
});
$('#photos').html($photos);
}
$(document).ready(function(){
$('button').click(
function(){
$('button').removeClass("selected");
$(this).addClass("selected");
var flickrAPI = "http://api.flickr.com/services/feeds/photos_public.gne?format=jsoncallback=?";
var animal = $(this).text();
$.getJSON(flickrAPI,{tags:animal,format:"json"},displayPhoto);
}
);
});
If I change displayPhoto
to jsonFlickrFeed
the code works, but I'm wondering why didn't the displayPhoto function work ?
1 Answer
Marcus Parsons
15,719 PointsHey George,
What's wrong is that your API url has a "format=" in there that shouldn't be there. Remove the "format=" from your API url so that it reads like so:
http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?
georgeprofenza
10,914 Pointsgeorgeprofenza
10,914 PointsI see, didn't pay attention to details there. Thank you
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsYou're welcome! :)