Has been blocked by CORS policy

I am usinf ionic4 for my application development.
The error bellow is happening in production apk build.

Access to XMLHttpRequest
from origin ‘http://localhost’ has been blocked by CORS policy: Request header field x-requested-with is not allowed by Access-Control-Allow-Headers in preflight response.

Can anyone help me?

Yes, do a Google search for CORS

Do you have control of the server?

If so, you need to enable…

Access-Control-Allow-Origin	*
Access-Control-Allow-Methods	OPTIONS,GET,POST,PUT,DELETE

…etc.

I enable Access-Control …

However is now presenting the following error

Failed to load resource: net::ERR_CONNECTION_REFUSED

Backend API is done on node.

Yeah, Google is your best bet for solving that.

Try using CORS extension:

1 Like