简体   繁体   中英

Get JSON from PHP url within AngularJS factory

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM