CORS issue when loading JSON in p5

Thanks GoToLoop. I tried several of the suggested browser extensions but none of them worked. Changing ‘json’ to ‘jsonp’ and adding ‘callback=getData’ to the tail of the url, however, did the trick. Dan Shiffman mentions this solution in his video https://thecodingtrain.com/Tutorials/10-working-with-data/10.4-loading-json-from-url.html :grinning:

function setup() {
  noLoop();
let url = 'https://api.flightstats.com/flex/schedules/rest/v1/jsonp/flight/AA/100/departing/2020/1/31?appId=XXX&appKey=XXX&callback=getData';
  loadJSON(url, getData, 'jsonp');
}

function draw() {
  background(200);
}

function getData(data) {
  let fly= data.request.carrier.requestedCode;
print(fly);
}
2 Likes