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

James Barrett
James Barrett
13,253 Points

Code not working in my own project?

Hi there!

Just trying the code Dave has done in my own project to see how it looks. Here is what I have:

JS:

$('#photobutton').click(function() {
    var flickerAPI = "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";
    var flickerOptions = {
        tags: "cats",
        format: "json"
    }
    var displayPhotos = function(data) {
        var photoHTML = '<ul>';
        $.each(data.items, function(i, photo){
            photoHTML += '<li>';
            photoHTML += '<a href="' + photo.link + '"';
            photoHTML += '<img src="' + photo.media.m + '"></a></li>';
        });
        photoHTML += '</ul>';
        $('#photos').html(photoHTML);
    }
    $.getJSON(flickerAPI, flickerOptions, displayPhotos)
});

index.php

<div id="photos">
      <button id="photobutton" type="button" class="btn btn-primary">Reveal Images!</button>
    </div>

Here is what's showing:

https://i.gyazo.com/9378235fd77b1739795a5a99ee795923.png

No console errors.

Also, why does my button disappear? I haven't programmed the JavaScript to do this?

Thanks, James.

2 Answers

Go into your developer console and check out the 'elements' tab. That will show you the HTML that the browser is rendering. Take a look at your <div> and see what got output by your program.

James Barrett
James Barrett
13,253 Points

Just found the problem, was a missing '>'!! Took me too long.

Thanks!