Note that although this question references wikidata, it is really a javascript fetch question. Also, this is not the wikidata api. I’m just trying to load a simple page from a url.
I want to access wikidata using a QID. My code generates a URL like
https://www.wikidata.org/wiki/Q111943988
which works from the browser (try it). But when I try to get it by calling fetch from the js script in my web page I get errors. Here is my code …
const wdataResp = await fetch("https://www.wikidata.org/wiki/Q111943988",
{method: "GET",
mode: 'no-cors',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' +
'AppleWebKit/537.36 (KHTML, like Gecko) ' +
'Chrome/131.0.0.0 Safari/537.36'}
});
It gives this response …
wdataResp: Response
body: null
bodyUsed: false
headers: <weird set of functions here>
ok:false
redirected:false
status:0
statusText:""
type:"opaque"
url:""
Note the ok:false
. I don’t think this is a cors problem. I got cors errors from this code and the mode: 'no-cors'
fixed it.
Can someone give me ideas on how to fix this? Thanks in advance.
2