I am trying to make a $http.jsonp call but the promise service is returning blank without data:
Below is my Js code
diary.factory('SongInfo', function ($http,$q) {
return {
//Return All Available Songs from the Database
getAllSongs : function () {
var defer = $q.defer();
$http.jsonp('http://fashion.c-research.in/api/?getsongs&name=JSON_CALLBACK')
.then(function (res){
defer.resolve(res.data);
})
return defer.promise;
},
//Get Song using the particular ID
getSongInfo : function (trackid) {
var defer = $q.defer();
$http.jsonp('http://fashion.c-research.in/api/?trackid='+trackid+'&name=JSON_CALLBACK')
.success(function(res){
defer.resolve(res);
})
.error(function (err){
defer.reject(err);
});
return defer.promise;
}
}
});
here is the Controller function:
diary.controller('PlayController', ['$scope', 'DeviceReady', 'SongInfo', function($scope, DeviceReady, SongInfo) {
var promise = SongInfo.getAllSongs();
promise.then(
function (payload) {
console.log(payload);
}
)
}]);
Nothing is being queried from the API.. Inned way to oreate
resolvebut notreject. It might be returning an error which you can't catch if you don't have areject. In other words, you're catching the success but not the fail/error. You should make yourgetAllSongslike thegetSongInfofunction.