JavaScript AJAX Basics (retiring) AJAX and APIs Stage 4 Challenge Answer

Frantyk Andrii
Frantyk Andrii
35,423 Points

Code doesn't work on Workspaces

When I use Workspaces, and try to follow for the teachers, my code doesn't work when I press preview button, and it doesn't display anything. But, when I use my own text editor, it works correctly. And I have a question, why workspaces doesn't work? Sometimes it easy to use workspaces following lecturer, rather than text editor. I it can be fixed?

2 Answers

rydavim
MOD
rydavim
Treehouse Moderator 17,951 Points

When you try to preview and get a blank page, are you getting any errors if you look at your browser's developer tools?

It's possible it's just not updating to the newest code version. I would try closing the workspace and reopening it, refreshing the preview page, and clearing your browser's cache to see if any of those steps solve the problem.

Same issue here, code just doesn't work.

$(document).ready(function() {


$('form').submit( function(evt){
  evt.preventDefault();

  var $searchTerm = $('#search');

    // the AJAX part
    var flickerAPI = "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";
    var animal = $searchTerm.val();
    var flickrOptions = {
      tags: animal,
      format: "json"
    };
    function displayPhotos(data) {
      var photoHTML = '<ul>';
      $.each(data.items,function(i,photo) {
        photoHTML += '<li class="grid-25 tablet-grid-50">';
        photoHTML += '<a href="' + photo.link + '" class="image">';
        photoHTML += '<img src="' + photo.media.m + '"></a></li>';
      }); // end each
      photoHTML += '</ul>';
      $('#photos').html(photoHTML);
    }
    $.getJSON(flickerAPI, flickrOptions, displayPhotos);

  }); // end click

}); // end ready