jsheroes / community-help

Helping others is fun, ask away and the ClujJavaScripters community will help you!
15 stars 0 forks source link

[Beginner] How can I solve "XMLHttpRequest cannot load file URL No 'Access-Control-Allow-Origin'"? #15

Closed cristianioann closed 7 years ago

cristianioann commented 7 years ago

Hey guys,

I was writing my Local Weather App locally. After that I wanted to port it on CodePen so I can complete my request exercise from freeCodeCamp. Locally, the app is fine and I have no errors in console, but after I copied the code in CodePen I started to have problems with getCurrentPosition() method.

Do you have any idea how can I solve this issue without investing much time into it? Here is the link to CodePen: Local Weather App I also tried with http, without any success.

Thanks in advance for your help.

raulGX commented 7 years ago

Google Chrome can't make XHR requests over http. What that means is that you can't make an AJAX call to an api that serves information on a non secure http protocol (https yes, http no). Also you don't really need the geolocation api (you can get longitude and latitude from the first ajax call "loc": "47.1667,27.6000").

PS1. Try to chain the 2 ajax calls somehow this is the purpose of this exercise. PS2. People on freecodecamp's forum/gitter are very friendly and helpful you should try asking there for a faster response.

cristianioann commented 7 years ago

All right. I finally found the solution. A guy had the same problem as me and posted a video on youtube: Here is the video