Random Quote Generator cant get quote

Random Quote Generator cant get quote
0

#1

Right now I’m trying to display a quote and then use the NEW QUOTE button to display a different one. I can’t seem to get any of the json to show up .

Btw im using the forismatic API and wasn’t able to find much documentation at all

Codepen link:


#2

Check your browser’s console (Ctrl+Shft+J in Chrome) and you will see an error message related to you trying to access and insecure page (http://) instead of a secure page (https://). Also, your url is incorrect. You should use:

https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?

Now, at first glance you would think this is all you need to do, but since you are using an anchor tag for your “click” event, you need to prevent it from trying to load a link. Even though you have href="", the page basically loads itself again instead of executing the code in your getJSON call. To prevent that, you need to add an argument (let’s call it event) to your click callback function. Then, add a new line above your getJSON line like:

event.preventDefault();

This should get you a quote.


#3

Thank you! That would have taken me forever to figure out