0

I have found the following JSON resource for global COVID infection data:

https://opendata.ecdc.europa.eu/covid19/casedistribution/json/

I have tried this simple callback function (And many variations) to verify I am in fact receiving something back that I can parse:

<script>
mycallback=function(data){
console.log('You have data! '+data)
};
</script>
<script src='https://opendata.ecdc.europa.eu/covid19/casedistribution/json/?callback=mycallback'> 
</script>

But this returns a big fat nothing, no console log entry, and no error code.

What am I doing wrong?

If anyone has tips on how to 'Parse' this 'data' that would also be appreciated, since I understand what I am getting is technically a script, but I could use it even if I treated the response as raw text.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Edward
  • 37
  • 1
  • 9
  • You can’t use JSONP, because the response from `https://opendata.ecdc.europa.eu/covid19/casedistribution/json/?callback=mycallback` isn’t executable JavaScript code (which is what JSONP is) but is instead just JSON data. So what you’re getting back isn’t actually technically a script — because it seems like that endpoint isn’t set up with JSONP support, so your `callback` query param has no efffect. – sideshowbarker Oct 18 '20 at 00:16
  • 1
    What you probably want to do instead is, use the fetch API or XHR or some ajax function from a JavaScript library, but use `https://cors-anywhere.herokuapp.com/https://opendata.ecdc.europa.eu/covid19/casedistribution/json/` as the request URL. For an explanation, see the answer at https://stackoverflow.com/a/43881141/441757 – sideshowbarker Oct 18 '20 at 00:18

1 Answers1

-1

You could do something like an http get request accompanied with a CORS proxy, and then just do JSON.parse on the returned data ¯_(ツ)_/¯