CORS Error in ionic

#1

hi i am trying to post the data to another domain using $http.post i found the cors error in my console. But the cors was enabled on both sides. can any one help me out how to fix this problem and how to post the data to different server without cors issue. i am using ubuntu and i am getting two errors here

The error is
1.OPTIONS http://somedomain/api/login 404 (Not Found)

2.XMLHttpRequest cannot load http://somedomain/api/login. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost’ is therefore not allowed access.

#2
#3

Here is something that helped me :smile:

#4

Answer here: Making REST call from Ionic

#5

You can use the Ionic proxy feature to get around CORS while you develop. This does not solve it for production apps though, since they won’t be running with ionic serve.

http://ionicinaction.com/how-to-fix-cors-issues-revisited/

#6

Hi better to add ‘Access-Control-Allow-Origin:*’ extension to Google Chrome
then We can solve CORS error

1 Like
#7

During testing locally, this is an easy win - props!

#8

I have problem

in ionic serve cors is working in browser but not working apk

. In the browser (using ionic serve) it was working properly , but in apk (using ionic build android ) it was not working…

cordova plugin add cordova-plugin-whitelist (I have added this puigin using CLI)

I have used these things in config.xml

ionic.project
{
“name”: “sampleApp”,
“app_id”: “a2fbab8f”,
“proxies”: [
{
“path”: “/api”,
“proxyUrl”: “http://myserver/api
}
]
}