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?

2
  • 1
    stackoverflow.com/questions/15381105/… Commented Nov 28, 2014 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. Commented Nov 28, 2014 at 11:13

1 Answer 1

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".

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.