Random Quote - No Result On Click

Random Quote - No Result On Click
0

#1

Hi everyone,

I’m having trouble with generating a quote after clicking the button. I checked my API url Forismatic API and to make sure that it is in the right format. I’m not sure at this point what is wrong with my code. Perhaps, the code in my getJSON is not finished or perhaps I’m missing something. I would appreciate any suggestions or tips in steering me into the right way.

Here is my codepen for the project: Random Quote CodePen


#2

If you open the console, you will see an error:

“Failed to load https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://s.codepen.io’ is therefore not allowed access.”


#3

You will need to use the following url per the documentation.

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

#4

Thank you, randelldawson & r1chard5mith!

Is there a reason why the url accepts jsonp as the format but not json? Since json is also one of the supported formats listed on the documentation, I thought my url is corrected. Does this have to do with writing my code in codepen?


#5

And your suggestions solve my problem. Thank you so much!