-1

I have created this ListFactory

factory('ListFactory', ['$resource', function ($resource) {
//   var Chiamate = $resource('http://samedomain.com/file.json', {}, {
   var Chiamate = $resource('http://anotherdomain.com/file.json', {}, {
    query: {
//            method: 'JSONP',
        method: 'GET',
        isArray: true,
        cache : false,
    }
});

return {
  query: function(id) {
        chiamate = Chiamate.query();
     return chiamate;
  }
};
}]);

in the controller i call the Factory using $scope.results = ListFactory.query();

and into html i show the results {{results}}

if i try to download a json file in same domain http://samedomain.com/file.json using method: 'GET', => ok i see the resource

if i try to download a json file in another domain http://anotherdomain.com/file.json using method: 'GET', => KO i see this error:

XMLHttpRequest cannot load http://anotherdomain.com/file.json No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://anotherdomain.com/file.json' is therefore not allowed access.

if i try to download a json file in another domain http://anotherdomain.com/file.json using method: 'JSONP', => KO i don't see any error, but i don't see the result:

i use https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js

Any idea? Can you help me to get json file on another domain?

Janka
  • 1,908
  • 5
  • 20
  • 41
  • do you have some server-side code transforming your json to jsonp? If not, you're only option is to do this with another technology, such as server-side php/asp/node etc. or to implement CORS on anotherdomain.com. – Kevin B Feb 11 '15 at 15:26

1 Answers1

0

You will need the co-operation of the remote site for this to work. They need to send a Access-Control-Allow-Origin with your site name, otherwise the browser will throw the error you have seen.

See the following stackoverflow question, which has a more detailed answer

How does Access-Control-Allow-Origin header work?

Community
  • 1
  • 1
thedoctor
  • 1,498
  • 1
  • 12
  • 12