![](/img/trans.png)
[英]Access to fetch has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
[英]fetch has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
我正在使用来自https://www.football-data.org 的api 制作这个网络应用程序
当我为网络制作样板时,我在控制台中收到此错误
const ENPOINT_JER = `${BASE_URL}competition/2002/standings`;
const ENPOINT_BEL = `${BASE_URL}competition/2003/standings`;
const ENPOINT_ING = `${BASE_URL}competition/2021/standings`;
const ENPOINT_SPA = `${BASE_URL}competition/2014/standings`;
const ENPOINT_PER = `${BASE_URL}competition/2015/standings`;
const fetchAPI = (url) => {
return fetch(url, {
headers: {
"X-Auth-Token": API_KEY,
},
})
.then((res) => {
if (res.status !== 200) {
console.log(`Error: ${res.status}`);
return Promise.reject(new Error(res.statusText));
} else {
return Promise.resolve(res);
}
})
.then((res) => res.json())
.catch((err) => {
console.log(err);
});
};
function getStandingJer() {
if ("caches" in window) {
caches.match(ENPOINT_JER).then(function (response) {
if (response) {
response.json().then(function (data) {
console.log("Competition Data: " + data);
showStanding(data);
});
}
});
}
fetchAPI(ENPOINT_JER)
.then((data) => {
showStanding(data);
})
.catch((error) => {
console.log(error);
});
}
我已经创建了 API_KEY 变量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.