Search code examples
javascriptajaxapisame-origin-policy

Issue with fetching data from a web api


So I started watching a tutorial on how to fetch data from a web api, and the first line of code that the instructor writes is this.

fetch('https://www.metaweather.com/api/location/2487956/')

He then explains that you can't fetch data from a website that isn't yours because of the same origin policy and uses a workaround which is using the crossorigin.me site. It works for him in the video, but doesn't work for me and it always gives me this error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.metaweather.com/api/location/2487956/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)

I've been looking for over an hour and I couldn't find a single solution. I'd really appreciate it if someone could help me out.


Solution

  • Or u can use a cors plugin for chrome and use it