Help with forismatic API for random quote generator project?

Help with forismatic API for random quote generator project?
0

#1

Hey everybody! First time poster here, go easy on me! :slight_smile:

So I’ve been working on the random quote generator intermediate front-end project. In my search for an API to use to generate the quotes, my frontrunner was the Forismatic API at forismatic.com. It’s free and unlimited which suits my needs perfectly, except for one problem: I just can’t get it to work! I keep getting a CORS error which says I am not allowed access because “no access-control-allow-origin header is set on the requested resource”. I read the CORS documentation to see if I could find a solution, but I couldn’t understand much of it. Help? Here’s a link to my codepen project: https://codepen.io/Vetsen86/pen/YEBMmp

The relevant get request is commented out near the top of my JS code. I went ahead and hard coded an object with a bunch of quotes in it to continue with the project, but I’d really like to do it with an API. Please help!


#2

There are a couple of options to use the forismatic API. One is to use a CORS proxy. Another is to use JSONP method. The latter has some potential security implications, so you should only use it with a trusted site. There is a great thread on the forum (see below) which discusses using JSONP and/or CORS.