0

I'm trying to use the MediaWiki Wikipedia API to make simple searches to Wikipedia. For some reason, when I use the Fetch API, it doesn't work. Here is my code:

const text = document.getElementById('content');

fetch('https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&srlimit=100&srsearch=apple')
  .then(res => res.json())
  .then(json => text.innerHTML = 'Success!')
  .catch(err => text.innerHTML = 'Failure :(');
<div id="content"></div>

When I use Chrome to go to the link that I am making a request to, it seems to work fine. What am I doing wrong in the JS?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
JakAttk123
  • 1,646
  • 3
  • 11
  • 19

0 Answers0