0

When I use axios to send a XMLHttpRequest, it occurs.

error: XMLHttpRequest cannot load https://nuxt-auth-routes.glitch.me/api/login. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

alex wong
  • 1
  • 2
  • 1
    that's because of the CORS issue - see **[CORS DOCUMENTATION](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)** – Jaromanda X Aug 02 '18 at 02:47
  • 1
    Cross-origin requests are only permitted when the remote server agrees to support them, by responding with JSONP or CORS-related headers (e.g. Access-Control-Allow-Origin). Client-side code can't force the request to succeed on its own. [Related](https://stackoverflow.com/a/27139956) – Jonathan Lonowski Aug 02 '18 at 02:59

1 Answers1

0

Try enabling CORS using this Chrome extension: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en

CORS

Explanation as to why: https://medium.com/@electra_chong/what-is-cors-what-is-it-used-for-308cafa4df1a

JDR
  • 107
  • 7
  • thanks, but I want to solve it with all browsers, not only chrome. – alex wong Aug 02 '18 at 02:52
  • You would then have to enable CORS on the server. If using Apache - https://enable-cors.org/server_apache.html. If using Nginix - https://enable-cors.org/server_nginx.html. Hope that helps. – JDR Aug 02 '18 at 02:56