Reputation: 2540
I get this response when I try to use 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, …}
The correct response is a JSON format of requested data, but I can't get it!
Here's my code:
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;})
Can anyone help me?
Upvotes: 1
Views: 121
Reputation: 982
try this 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);
});
Upvotes: 2
Reputation: 5309
try this: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));
Upvotes: 1