当我尝试使用 Wikipedia API 时收到此响应
> 响应 {type: "cors", url: "https://en.wikipedia.org/w/api.php?action=opensear…amespace=0&format=json&origin=*&utf8=&format=json", redirected : false, status: 200, ok: true, ...}
正确的响应是一个json格式的请求数据,但是我获取不到!
这是我的代码:
let link = `https://en.wikipedia.org/w/api.php?action=opensearch&search=google&limit=20&namespace=0&format=json&origin=*&utf8=&format=json`;
fetch(link)
.then((res)=>{console.log(res);return res;})
谁能帮帮我?
最佳答案
试试这个 Example
fetch('https://en.wikipedia.org/w/api.php?action=opensearch&search=google&limit=20&namespace=0&format=json&origin=*&utf8=&format=json')
.then(function(response) {
return response.json();
})
.then(function(myJson) {
console.log(myJson);
});
关于javascript - 当我获取 wikipedia api 时得到错误的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49594421/