Api isnt working in my random quote machine

Api isnt working in my random quote machine
0

#1

When I console logged the quoteText it returns an error.Can you reason out why?


#2

Not without a link to your codepen project so we can see what may have gone wrong! I’ll take a look if you leave the link.


#3

Oh sorry, I forgot it here is the link to my project


#4

So the issue was in your url. Change it to http://api.forismatic.com/api/1.0/?method=getQuote&key=457653&lang=en&format=jsonp&jsonp=? If you replace this your console log will show the quote text.

You’ll see it’s very similar to your original url except the format has been changed to jsonp, with &jsonp=? added to the end. Now why does it work with jsonp and not just json? Unfortunately I can’t remember. I ran into this very problem when I did the project. Hopefully someone here more knowledgeable can give you the reason why this change was needed! :slight_smile:


#5

I’ve changed it but it still doesn’t work


#6

Now it works but i have to load codepen using http instead of https.


#7

Glad you got that working!