I have been developing my REST calls locally on Chrome with the CORS disabled.
I had read that CORS is not an issue with PhoneGap-based apps.
My app works fine calling a remote server for REST requests via $http.
When I deploy my app to the emulator
the http calls are returning 404, I believe a symptom of CORS as this is the behavior I was getting in Chrome before I disabled CORS.
Are there any best practices for handling this?
oh man, fighting CORS can be quiet a headache.
in your config try putting:
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
and make sure to inject $httpProvider into your config.
Also, make sure to handle preflight on the server side.
P.S. if it’s a 404, I don’t think it is necessarily CORS related. I believe you should be getting a 500
Since you’re getting a 404 and it’s working in chrome I don’t think this is a CORS issue. Are you emulating on iOS or Android? You can open the web inspector on either to check the status of your preflight.
https://developer.apple.com/safari/tools/
Make sure you’re still not trying to hit localhost because this will not work on a device/emulator.
I got CORS working by just enabling it on my server (node.js) and I didn’t have to do anything like @mlovekovsky 's suggestion.
http://enable-cors.org/