Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    CORS error while trying to make http request

    Scheduled Pinned Locked Moved
    Duet Web Control
    2
    3
    530
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • e4dundefined
      e4d
      last edited by

      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.

      MintyTreborundefined 1 Reply Last reply Reply Quote 0
      • MintyTreborundefined
        MintyTrebor @e4d
        last edited by

        @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...

        NodeDSF - Native Node-Red integration with Duet boards.
        BtnCmd - Customise DWC with user defined buttons/layouts/panels (DWC Plugin)
        ReleaseMgr - Duet update info inside DWC.
        Repo

        e4dundefined 1 Reply Last reply Reply Quote 1
        • e4dundefined
          e4d @MintyTrebor
          last edited by

          @mintytrebor thank you for your answer, it works great now

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Unless otherwise noted, all forum content is licensed under CC-BY-SA