0

I am trying to load .json file which have some setting data

server.js code

(function () {
app.factory("configService", ['$http', function ($http) {
    return {
        getResponders: function () {
            var url = 'https://example.com/assets/js/service/config.json',
            apiHeaders = {
                'Access-Control-Allow-Origin': '*',
                'Content-Type': 'application/json;charset=utf-8'
            };

            return $http({
                   method: "GET",
                   url: url,
                   headers: apiHeaders,
                   data: {}
            }).then(function (res) {
                console.log('response : ' + res);
            }, function (res) {
                console.log('error : '+res);
            });

        }
    };
}]);

})();

and tying to get res but it show error:

Failed to load https://example.com/assets/js/service/config.json: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8678' is therefore not allowed access. The response had HTTP status code 403.

1 Answer 1

1

All HTTP calls that you make in Angular are making AJAX calls in the background. As such it respects all the CORS rules.

The called script needs to allow you access. If it doesn't do that you can't force it.

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

Comments

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.