-1

I was trying to build a horoscope app with Vanilla JavaScript. I am using fetch API to get horoscope details with this API.

I get this error in the console:

No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'https://pratik-pdw.github.io' is therefore not allowed access.
If an opaque response serves your needs, set the request's mode to 'no-cors' 
to fetch the resource with CORS disabled.

I have deployed the app as a Github Page.

perror
  • 7,071
  • 16
  • 58
  • 85
Pratik Wadekar
  • 1,198
  • 8
  • 15

1 Answers1

1

Your browser is blocking it as it usually allows a request in the same origin for security reasons. You need to do some additional when you want to do a cross-domain request.

Full refrence about CORS https://www.html5rocks.com/en/tutorials/cors/

You can try with the below:

  1. Open the chrome browser which allow access to no 'access-control-allow-origin' header request.

    chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security

  2. Try with XDomain,

    XDomain is a pure JavaScript CORS alternative/polyfill. No server configuration required - just add a proxy.html on the domain you wish to communicate with. This library uses XHook to hook all XHR, so XDomain should work in conjunction with any library.

NullPointer
  • 7,094
  • 5
  • 27
  • 41