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 trial

JavaScript AJAX Basics (retiring) AJAX and APIs Displaying the Photos

Not working

$(document).ready(function(){
  $("button").click(function(){
    $(this).removeClass("selected");
    $(this).addClass("selected");
    //url
    var flickerAPI = "https://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";
    //query string telling flicker we're making a jsonp request
    //grab text from buttons
    var animal = $(this).text();
    //data in object form
    var flickrOptions = {
      tags: animal,
      format: "json"
    };
    function displayPhotos(data) {
      var photoHTML = '<ul>';
      //loop through each of the photos from the flicker feed
      $.each(data.items, function(i, photo) {
        photoHTML += '<li class="grid-25 table-grid-50">';
        //link to the flicker page for the image
        photoHTML += '<a href="'+ photo.link +'" class="image">';
        photoHTML += '<img src= "'+ photo.media.m + '"></a></li>';
      });
      photoHTML += '</ul>';
      //add string to html of page
      $('#photos').html(photoHTML);
    }
    $.getJSON(flickerAPI, flickrOptions, displayPhotos);
  });
});
Sean T. Unwin
Sean T. Unwin
28,690 Points

I have edited your post so the code example displays properly. Please see this post regarding posting code - https://teamtreehouse.com/forum/posting-code-to-the-forum. :)

2 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

On line:

photoHTML += '<img src= "'+ photo.media.m + '"></a></li>';

There is a space between src= and the double quotation marks. Remove the space:

photoHTML += '<img src="'+ photo.media.m + '"></a></li>';

A very subtle error, yet significant. :)

Thank you!!!