0

I'm trying to get user details from the Github API using fetch, but it's showing the following error in the console

Access to fetch at 'https://api.github.com/users/a' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

How to solve this problem

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Cyborg7459
  • 157
  • 3
  • 10
  • 2
    Does this answer your question? [No 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API](https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe) – Edric Jun 13 '20 at 20:49
  • strange, can you try [this fiddle](https://jsfiddle.net/marvel92/bn19qfju/1/) does it show an alert with the result ? – Bertrand Martel Jun 13 '20 at 21:42

1 Answers1

0

Even if the error message includes "CORS", there are other things wrong.


The following content that is my original answer has nothing with this question.

It is the problem of the browser and localhost not GitHub API. (To tell the truth, GitHub API allow CORS)
Normal browsers must disturb the connection between localhost and http(s)://*. If you want to avoid it, you should use http-server (npm install http-server -g).

tomo_iris427
  • 161
  • 6
  • Sorry, I've mistaken! Even from localhost, CORS is not important. Even if the error message includes "CORS", there are other things wrong. – tomo_iris427 Nov 12 '20 at 01:41