当我尝试使用Wikipedia API时,我得到了这个回复
> Response {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;})
任何人都可以帮助我吗?
答案 0 :(得分:2)
试试这个 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);
});
答案 1 :(得分:1)
试试这个:MDN
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 => res.json())
.then(data => console.log(data));