-1

I am getting this error using fetch method in JavaScript
Fetch Problem: unexpected end of input

     let myinit={
    method:'GET',
    mode:'no-cors',
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Connection': 'keep-alive',
        'Accept-Encoding' : 'gzip, deflate, br',
    },
    cache:'default'
};

let myRequest =new Request('https://opendata.ecdc.europa.eu/covid19/casedistribution/json/',myinit);
fetch(myRequest)
    .then(function(response){
        return response.json();
    })
    .then(function(data){
        console.log(data);
    })
    .catch(function (err) {
        console.log('Fetch problem: ', err.message);
    });

1 Answers1

1

Try this:

let myinit={
    method:'GET',
    // mode:'no-cors',
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Connection': 'keep-alive',
        'Accept-Encoding' : 'gzip, deflate',
    },
    cache:'default'
};
let myRequest =new Request('https://cors-anywhere.herokuapp.com/https://opendata.ecdc.europa.eu/covid19/casedistribution/json/',myinit);
fetch(myRequest)
    .then(function(response){
        return response.json();
    })
    .then(function(data){
        console.log(data);
    })
    .catch(function (err) {
        console.log('Fetch problem: ', err.message);
    });
Đinh Carabus
  • 3,403
  • 4
  • 22
  • 44