I tried to run this javascript code on a Tampermonkey userscript on many webpages but they all gave the same problem: (I modified some details)
var data="744483"; var url="https://example.com/test.php?data="+data; fetch(url).then(response => response.text()) .then((response) => {alert(response);})
but it gave this problem:
Access to fetch at ‘https://example.com/test.php?data=744483’ from origin ‘https://www.paxful.com’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.
Failed to load resource: net::ERR_FAILED
I tried this code but even though the code ran, no response was given back:
var data="744483"; var url="https://example.com/test.php?data="+data; fetch(url, { mode: 'no-cors'}).then(response => response.text()) .then((response) => {alert(response);})
Ryan Newman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.