I'm trying to learn how to call APIs using JQuery. I've created a little function to change the text inside of a div (class="quote-box"
). The function seems to work fine for the most part. Clicking the #newQuote
button changes the text in the div to Didn't work
.
However, the .getJSON
in the middle is doing nothing at all. I would expect this code to change the text to "Yay.", but it refuses to do anything inside of the function(json){ }
block.
--old code removed--
Any help would be greatly appreciated.
EDIT: This does not appear to be a duplicate of the above question, since the function continues to fail even after removing all variables.
$("#newQuote").on("click", function(){
$.getJSON("http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=json", function(json){
$(".quote-box").html("Yay");
});
});
EDIT 2: Solved. The forismatic API does not like https. Switching to normal http made everything work properly.