JavaScript提取API中的输出意外结束

我在JavaScript中使用提取方法收到此错误 提取问题:输入意外结束

     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);
    });
评论
妮听咱话
妮听咱话

尝试这个:

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);
    });
点赞
评论