Read the statement by Michael Teeuw here.
missing 'Access-Control-Allow-Origin'
-
I’ll try to grab some informations from a JSON Data feed.
But I’ve got always this error:Quellübergreifende (Cross-Origin) Anfrage blockiert: Die Gleiche-Quelle-Regel verbietet das Lesen der externen Ressource auf http://beny.ch/ironman/2015. (Grund: CORS-Kopfzeile 'Access-Control-Allow-Origin' fehlt). ironman: Could not load data. console.error(message);Datalink:
http://beny.ch/ironman/2015here is the code to grab the content:
var ironmanRequest = new XMLHttpRequest(); ironmanRequest.open("GET", url, true); ironmanRequest.onreadystatechange = function() { if (this.readyState === 4) { if (this.status === 200) { self.processIronman(JSON.parse(this.response)); } else if (this.status === 401) { self.updateDom(self.config.animationSpeed); Log.error(self.name + ": Error forbidden"); retry = false; } else { Log.error(self.name + ": Could not load data."); } if (retry) { self.scheduleUpdate((self.loaded) ? -1 : self.config.retryDelay); } } }; ironmanRequest.send();How can I fix that?
Thanks for helping me :-)
-
This comes up quite often, not just here on the MM² forums, but out in the wild too:
http://lmgtfy.com/?q=Access-Control-Allow-Origin
Basically the answer is: you can’t do that … cross-domain … security … find proper API … all of the above …
-
@KirAsh4 Well, not strictly true ;) https://forum.magicmirror.builders/topic/157/mmm-opentherm
But yes, you’ll need to fix the source! -
Just use a
node_helper.jsto get around the access-allow-origin policy. -
After googleing 1000 different websites I’ve used the
nood_helper.jssolution.And to load the nood_helper.js I had to restart electron.
pm2 restart mm
that coast me another hour to find out why it was no loading :-):gun: :hammer: -
I am facing the same problem. Could you please give an example, how you used node_helper.js to circumvent the access-allow-origin policy?
Thanks!
-
Like here for example:
https://github.com/yawnsde/MMM-RNVYou use request instead.
-
Thank you!
And why does it have to be in node_helper, not in the main script? Sorry, if this question sounds stupid, I’m new to developing modules.
Also, is there a reason for declaring var self = this; and using self.func instead of this.func? I have seen this quite a bit and couldn’t understand why people do this…
-
@KrawallKurt
Please note I am not an experienced javascript developer either. When using addon modules/libraries likerequestyou use thenode_helper.jsto load this library. I am not sure if it is not possible at all to do so in the main module file or if it is just complicated. Maybe @strawberry-3-141 can clarify :)self = thiswas used in other modules and I added it to my module as well, because I did not want to possibly break something by leaving it out. There is a lot of discussion on the web why this is used and if this still should be used. -
Concerning the self=this question, I found a neat article giving som explanations: https://alistapart.com/article/getoutbindingsituations
The other question: Could it be, that node_helper is executed on the server and the main script is executed on the client?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login