Problem with getJSON

Problem with getJSON
0

#1

Hi I’m trying to get json from an external website and displaying it on mypage I’ve tried a lot of thing but none of them work, here’s my code:

HTML

<body class = "bodyBackColor">
  <div class = "container-fluid">
    <div class = "quotes1">
  
    </div>
    <button id = "showQuote" class = "btn btn-primary">
      show Quote
    </button>
  </div>
</body>

JAVASCRIPT

$(document).ready(function() {
  $("#showQuote").on("click", function () {
    //$(".quotes1").html("das");

    $.getJSON("www.freecodecamp.com/json/cats.json", function(json) {
      //alert("das");
       $(".quotes1").html(JSON.stringify(json));
    });

  });
});

I’ve tried using($.getJSON("www.freecodecamp.com/json/cats.json?callback=?) and nothing, the click function is working, but after the getJSON it doesn’t do anything, I place an alert inside it but never shows, so please tell me what am I doing wrong.

Thanks.


#2

Check out the jquery api for it (http://api.jquery.com/jquery.getjson). The function uses what is called a promise which means you can chain on a done () and fail() method. What I would do is implement those and see if any errors are returned in the fail() part of the promise then go from there.