I’ve developed the Random Quote Machine as an Express.js app in local. I copy-pasted my code on CodePen to submit my work for the challenge and it seems that the page isn’t sending requests. I’ve been trying to
understand why but I haven’t yet figured it out. I’m using plain vanilla javascript and everyone here it’s using jQuery/ajax, so I’m not quite sure how to proceed.
The app was designed around quotesondesign
's API and it works on localhost!
The XMLHttpRequest.onerror
gets fired instead of XMLHttpRequest.onload
.
I tried forismatic’s API https://forismatic.com/en/api/ but I couldn’t get it to work, neither on codepen nor on localhost. I think I’m missing something, but I don’t know what!
Any ideas?
Looks like a cross-origin issue. Try adding this to the start of the URL on your API call https://cors-anywhere.herokuapp.com/
Have you tried changing your http request to an https request? I just did and your app worked for me.
1 Like
Thanks!
Both solution helped! I tried to use https
before but it was receiving the same quote every time. I luckily found another Pen which used the same API and he adds a random number at the end of the request URL: I guess CodePen caches the response and that was preventing new quotes to come in?
I changed a bit and used Math.random() * 1000000
instead of new Date.getTime() / 1000
and now it’s working!
Tomorrow I’ll check if I can set some cache headers and make it work without the random number, thanks for now!
2 Likes