0
votes

In my Ionic 4 Angular project I get the following error when requesting a json file from a server in my iOS simulator.

XMLHttpRequest cannot load https://myServer.com/api due to access control checks. cordova.js:1540

Failed to load resource: Origin ionic://localhost is not allowed by Access-Control-Allow-Origin.

In the Chrome Browser with Access-Controls-origin plugin I do not get the error. How can I fix this issue?

2
please specify with server-side technology your using - Shailesh Bhokare

2 Answers

0
votes

Follow this link - 3 Ways to Fix the CORS Error — and How the Access-Control-Allow-Origin Header Works. The first option (install the moesif CORS extension) worked for me.

CORS errors are common in web apps when a cross-origin request is made but the server doesn't return the required headers in the response (is not CORS-enabled). It only happens when you're running the app from your localhost for testing purposes.

-1
votes

You need to add ("Access-Control-Allow-Origin", '*') header at the requested resource.