Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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?

share|improve this question
1  
    
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 Answer 1

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

share|improve this answer
    
pls post answer's only when you are sure it works.. –  ThePredator Nov 28 '14 at 11:25
    
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 1 '14 at 12:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.