Problem with $.getJSON()

Problem with $.getJSON()
0

#1

I was trying to use and execute the “Get JSON with the jQuery getJSON Method” lesson´s code in codepen (of course placing the code blocks in their respective categories, HTML, CSS and javascript) to see if it works, but it doesn´t :(… it just shows me the title, shadowed text and button, but the button does nothing. Please help…

Here´s the code:

<script>
  $(document).ready(function() {

    $("#getMessage").on("click", function(){
      // Only change code below this line.
      
      $.getJSON("/json/cats.json", function(json) {
  $(".message").html(JSON.stringify(json));
});
      
      // Only change code above this line.
    });

  });
</script>

<div class="container-fluid">
  <div class = "row text-center">
    <h2>Cat Photo Finder</h2>
  </div>
  <div class = "row text-center">
    <div class = "col-xs-12 well message">
      The message will go here
    </div>
  </div>
  <div class = "row text-center">
    <div class = "col-xs-12">
      <button id = "getMessage" class = "btn btn-primary">
        Get Message
      </button>
    </div>
  </div>
</div>

#2

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard.


#3

Put a link to your Codepen so we can see how you have everything setup on there.

EDIT: You are trying to link to a local file in the following line which is not possible, because Codepen does not have such a file. My guess is there are other problems with your setup, but I can check that out after you post the link.

$.getJSON("/json/cats.json", function(json) {

#4

That challenge should be done inside FCC interface, not on Codepen. You copied the code to Codepen, but the file /json/cats.json only exists inside FCC environment.