0

I am trying to access the dreamfactory data through $http request. To handle cross domain request, i have just added the JSON callback with the url.

.factory('DonorService', ['$resource','$http', '$q',
    function($resource,$http,$q){
    return{
        getDonors:function(){
            var donor = "https://dsp-sixerofsixes.cloud.dreamfactory.com/rest/db/icbd_donors/?callback=JSON_CALLBACK&app_name=blooddonate&fields=*";
            var deferred = $q.defer();
            $http.jsonp(donor).
            success(function(data, status, headers, config) {
                console.log(data);
                deferred.resolve(data);
            }).
            error(function(data, status, headers, config) {
                console.log(data);
            });
            return deferred.promise;
        }
    }
}])

But on making the request it creates a internal server error in the df. while typing the url in the browser shows the data along with wrapping callback.

Link to the JSON data

Link which is actually called from JSONP

Pamsix
  • 129
  • 1
  • 3
  • I see it properly too. Can you diagnose the internal server error? – Kevin B Nov 10 '14 at 20:25
  • Might also be a good idea to look at the request parameters sent using the network tab of the console(F12). – Kevin B Nov 10 '14 at 20:26
  • It seems to be an angular convention that JSONCALLBACK is converted to angular.callbacks._0. Thus making a request as [link](https://dsp-sixerofsixes.cloud.dreamfactory.com/rest/db/icbd_donors/?app_name=blooddonate&fields=*&callback=angular.callbacks._0) instead of the above one. – Pamsix Nov 11 '14 at 02:17

1 Answers1

0

I can't comment yet, so I guess I'll have to write this here.

Remove the resource injection. Just use $http.

ngResource incrementally creates those angular callback names.