Hey guys,
So I have a backend service (currently running on my localhost) and I have my ionic app (also running on my localhost).
I am trying to make a super simple ajax call to my backend, however I just can’t get it to work.
My app config looks like this:
// Define the HTTP config to enable CORS API calls
airborneApp.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
$httpProvider.defaults.headers.common = 'Content-Type: application/json';
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}
]);
My service looks like this:
app.service('ExperienceService', function($http) {
this.getExperiences = function() {
// Since $http.get returns a promise, and promise.then() also returns a promise
// that resolves to whatever value is returned in its callback argument,
// we can return that.
return $http({method: "GET",
url: 'http://localhost/goairly/trunk/monumentus/index.php/api/experience/experience',
}).success(function(result) {
return result.data;
}).error(function(data, status, headers, config) {
console.log("error");
console.log(data);
console.log(status);
console.log(headers);
console.log(config);
});
};
});
My Chrome console outputs 404 (Not Found). Further more it sends it as OPTIONS instead of GET. When I go to the Network tab and inspect the request itself, I notice that the request does not have Content-Type: "application/json"
, which is necessary for us to access our server. However, it seems that that header is removed altogether.
EDIT I tested the URL, with Advanced Rest Client Chrome plugin and it works just fine. When I compare the two headers (from chrome and from the advanced rest client) the main difference is the content-type.
Anybody else running into this?