3

Access to XMLHttpRequest at 'http://localhost:8080/ws' from origin 'http://localhost:3001' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • are you using express js? – Raphael Castro Jan 19 '20 at 20:45
  • I got this error last week. I solved the problem by adding the following phrase to the package.json. "proxy": "YourAPIUrl". Please try it and return back. – Alperen ARICI Jan 19 '20 at 21:33
  • Does this answer your question? [XMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' header](https://stackoverflow.com/questions/35553500/xmlhttprequest-cannot-load-xxx-no-access-control-allow-origin-header) – Quentin Dec 08 '21 at 15:04

1 Answers1

0

When invoking an XMLHttpRequest, the browser makes a preflight request and checks for an Access-Control-Allow-Origin header to determine whether the request should be allowed. You should edit your server code to send that header with a value that allows the domain of your client (or just * to allow CORS requests from any origin). For example, if using a Node server with Express, you could do res.set('Access-Control-Allow-Origin', '*')

programmer
  • 743
  • 4
  • 10