cryptofanatic09
cryptofanatic09

Reputation: 21

I am new to APIs. Why is my request to get the JSON of one not working?

I already have the code below inside of a $(document).ready(function() inside of a click event handler that is activated once a user presses a button. Once a user presses the button, the API should be requested and the JSON from it be retrieved for me to play with. For some reason, however, every time I try to make the $.getJSON() request, nothing will happen. Here is all of the jQuery code I have for the website and yes, I have made sure everything else works like the event handler by testing it out on other elements.

$(document).ready(function() {
     $("#new").click(function() {
      $("body").css("background-color", changeColor());
      $("#bigContainer").css("background-color", randie);
      $.getJSON("http://quotesondesign.com/wp-json/posts", function(json) {

         $("#qbox").html(JSON.stringify(json));

        });
      });

    });

Thankyou.

Upvotes: -1

Views: 45

Answers (1)

Moaead Yahya
Moaead Yahya

Reputation: 211

You said you use codepin they force https and you are doing http request so this won't work because of Mixed Content policy. Please change the url to be

$.getJSON("https://quotesondesign.com/wp-json/posts", function(json) {

notice the https.

Upvotes: 3

Related Questions