Fetch() With The Wikipedia Api Results In "typeerror: Networkerror When Attempting To Fetch Resource."
fetch('https://en.wikipedia.org/w/api.php?action=query&titles=Main%20Page&prop=revisions&rvprop=content&format=json') .then( function(response) {
Solution 1:
The problem is due to fetch()
using CORS. However, when I changed to mode: "no-cors"
I was no longer blocked on Cross-origin request but given a status code of 0.
According to this documentation from google: https://developers.google.com/web/updates/2015/03/introduction-to-fetch?hl=en
" 'no-cors' is intended to make requests to other origins that do not have CORS headers and result in an opaque response, but as stated, this isn’t possible in the window global scope at the moment."
So currently to access the wikipedia api, one will have to use a different way than fetch()
Solution 2:
The answer above is correct. As to the comment on where to set the 'mode" just do this:
fetch(url, { mode: 'no-cors' })
Post a Comment for "Fetch() With The Wikipedia Api Results In "typeerror: Networkerror When Attempting To Fetch Resource.""