0

I have a AngularJS factory that has a method to get JSON from either a file on disk or from an URL.

The file approach is working okay. When I change it to use the remote URL, it isn't working. In Firefox it doesn't show me much information. I only get a warning about CORS or something? This is my code from the factory:

(function () {

var releasingFactory = function ($http) {

    var factory = {};

    factory.getCars = function(callback){

        //return $http.get('/wagenplan/releasing.json');      
    return $http.get('http://www.athloncarlease.com/webservice/releasing.php').success(callback);
    }

    return factory;
};

releasingFactory.$inject = ['$http'];

angular.module('releasingApp').factory('releasingFactory', releasingFactory);

}());

I'm not sure if this will work. The warning from FF Firebug is:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.athloncarlease.com/webservice/releasing.php. This can be fixed by moving the resource to the same domain or enabling CORS.

Any idea's?

Daniel Plomp
  • 176
  • 1
  • 12
  • 1
    http://stackoverflow.com/questions/15381105/cors-what-is-the-motivation-behind-introducing-preflight-requests – vaso123 Nov 28 '14 at 11:08
  • Not sure if I understand this. The URL seems to work anyways, since I get a result even through my browser. I'm not able to 'enable cors' on that remote server. – Daniel Plomp Nov 28 '14 at 11:13

1 Answers1

0

I have read the article on Wikipedia about Same-origin policy. Perhaps you should skip "www." in the location string to be aligned with the rule: "same protocol, host and port".

  • Generally you are right, thank you for this advice for the beginner. I have no access to environment of the colleague who is looking for help, but I have read an article related to this mechanism, I have tried to find a possible gap and then I have answered with the best answer - from my point of view. Something went wrong? ;-) I think not. Once again, thank you for the advice, it is generally good. – Gerard Jaryczewski Dec 01 '14 at 12:13