I am pulling in JSON from a file I am storing locally. When I view this in the browser it works, when I view it in an Ionic packaged app it returns 404
I am using the following code:
.factory('cardFactory', function ($q, $http, $rootScope) {
return {
getCards: function () {
var deferred = $q.defer(),
httpPromise = $http.jsonp('/static/cards.json');
httpPromise.then(function (response) {
deferred.resolve(response);
}, function (error) {
console.error(error);
});
return deferred.promise;
}
};
});
And calling it like so:
cardFactory.getCards()
.then(cardSuccess, cardError);
I have tried with GET instead of JSONP, both return a 404 response.
I am aware of the access-control-allow-origin issue, but surely the jsonP should solve that? This is at the same level (hierarchically) as my images, which are served fine.
Any ideas what's going on?
The solution was to change the request back to a simple GET, and lose the first slash as so:
var httpPromise = $http.get('static/cards.json');