gpt4 book ai didi

javascript - 无法从维基百科 API 获取数据

转载 作者:行者123 更新时间:2023-11-30 14:47:58 24 4
gpt4 key购买 nike

let dataObj = [];
const query = 'marvel';
fetch(`https://en.wikipedia.org/w/api.php?action=query&titles=${query}&prop=revisions&rvprop=content&format=json&formatversion=2`)
.then(data => data.json())
.then(data => dataObj.push(data))
.catch(err => console.log(err));

这是我收到的错误:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s.codepen.io' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

我将模式设置为 no-cors 但还是不行。

最佳答案

尝试添加查询参数 origin=* 来帮助解决 CORS 问题:

https://en.wikipedia.org/w/api.php?action=query&titles=${query}&prop=revisions&rvprop=content&format=json&formatversion=2&origin=*

希望对您有所帮助!

关于javascript - 无法从维基百科 API 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48604705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com