CORS error while trying to make http request
-
Hello,
I'm trying to develop a webpage which shows the state of all of my three Duet-based 3D printers. I made a webpage with a JS script that point to : http://192.168.1.102/rr_status?type=3. I struggle with a CORS error :Access to XMLHttpRequest at 'http://192.168.1.101/rr_status?type=3' from origin 'http://192.168.1.129' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. jquery.min.js:2 GET http://192.168.1.101/rr_status?type=3 net::ERR_FAILED 200
I've done some research and it always point me to something to do server-side. Since server is Duet here I don't really know how I can go past this.
Here's the JS code reduced to the simplest form which still don't work :
var obj; url = 'http://192.168.1.101/rr_status?type=3' let response = await fetch(url); if (response.ok) { // if HTTP-status is 200-299 let json = await response.json(); obj = json; } else { alert("HTTP-Error: " + response.status); }
I tried to access the page with my browser and I successfuly have the JSON in response. It doesn't work only with the script.
Can someone point me in the right direction ? I didn't found something like this on the forum so I think it can be relevant to others in the future. -
@e4d https://duet3d.dozuki.com/Wiki/M586 might help
I have to add M586 C"*" into my config.g to remove Cors errors when I am debugging/testing a DWC plugin, so it might work for you...
-
@mintytrebor thank you for your answer, it works great now