CORS Error with APIs and jQuery

Hi All,

I teach data visualization and have been using Glitch in the classroom. We are working on getting live data from APIs using jQuery and a number of my students are getting CORS errors. Do you know if there is anyway around this? Here is one student example.

Thanks!

Danne

Hey, welcome to the forum! I just looked at the console in your project. You need to remove the fonts under ‘assets.’ Specifically the illustration.svg. They came with the starter but they seem to be what’s throwing the errors. I recommend using Glitch’s ‘blank’ starters if you’re not using the extras that the regular ones come with.

Hi Danne,

From what I can see you cannot make the following getJSON call from your browser. You could set up a server in the project and funnel all the calls through there but it obviously would be a bit more work.

You should also see it work if you simply comment out that code as you aren’t really doing anything with the results.

$(document).ready(function() {
$.getJSON( “https://www.fruityvice.com/api/fruit/all”, function( data ) {
console.log(data);
});
})