Need help for random quote machine

Hi everyone, so after having tried different ways to pull the json file of the quotes and nothing seemed to work (keep getting the cross-origin problem, sometimes the request was rejected because the header for origin has the value “null” or something, when I tried using jsonp I encountered the incorrect MIME type error, haven’t tried the work-around that involves passing the origin domain to the “text/javascript” field though) , I came across a post that suggests that this happens because I ran the code from my laptop without having a local server, and running the code from CodePen would work just fine so I went and pasted my code on CodePen. The error stops showing, but still no quotes on the screen and I couldn’t figure out what is missing at the time since the console is blank.

Would appreciate if anyone could look through my code, apologize in advance if the problem was obvious : .

Edit: I needed to add ‘&callback=’ to the end of the url in order for it to work. if anyone encounters CORS problems, it could be that you are running the code from your local machine without a server. Try running it from CodePen or Jsfiddle. Have fun coding.

You’re getting an array as a response. You can access the quote by using json[0].content, etc.

1 Like

I thought the additional parameters in the url makes it so that only one quote is returned everytime, I copy-pasted the url in the address bar in Chrome browser and it seems to do just that, I could be wrong though.

That may be so, but that one quote is still inside an array. If you entered the URL in a browser, you should see square brackets on both ends of the response.

Oh yeah, feel kind of dumb now, thanks a lot! But the error is back though. Guess I’ll have to find other ways for this.