I am working through the tutorial examples, and when trying the book example from the Http section, I’m running into a snag. It works fine in the online emulator, but when I put it in atom and run it through reactor, I’m getting a NetworkError response. This was somewhat fortunate at first as it helped me learn about the response types and handling them, but now I can’t seem to work it out. I’ve tried it with different .txt URLs, and tried it on different networks (work network and mobile). The link to my modified code is above, although it produces the same result when copied straight out of the tutorial. Am I missing an import or some other structural/syntactical oversight?
Do you know how to use your browser’s debugging console? Press F12. You will then see this mesage:
Access to XMLHttpRequest at ‘https://elm-lang.org/assets/public-opinion.txt’ from origin ‘https://ellie-app.com’ has been blocked by CORS policy: The ‘Access-Control-Allow-Origin’ header has a value ‘https://worker.elm-lang.org’ that is not equal to the supplied origin.
Okay, thank you!! I pushed it through a generic CORS proxy I found on SO and it worked. I’m new to web development (very new) so this may be a silly question, but are these CORS denials common? Is it even advisable to use a CORS proxy?
Why does the browser not block the http request if I navigate there directly with the address bar?
Your code itself is working correctly, it’s just that the elm-lang.org server doesn’t allow you to fetch that file.
Try changing your URL to e.g.
https://www.markuslaire.com/ajax/TimeNowUTC.php which allows access to see that your code does actually work.
By default CORS access is not allowed. Server must specifically send
Access-Control-Allow-Origin header to allow access, so denials are really common.
Thanks for the input. I will keep a lookout for this sort of configuration error in future get requests.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.