0

I have this part of code

App.factory('httpRequestInterceptor', function () {
return {
    request: function (config) {

        console.log(config)
        config.headers['Access-Control-Allow-Origin'] = '*';
        config.headers['Access-Control-Allow-Methods'] = 'GET, PUT, POST, DELETE, HEAD, OPTIONS';
        config.headers['Access-Control-Allow-Credentials'] = 'true';
        config.headers['Access-Control-Allow-Headers'] = 'X-Requested-With, origin, content-type, accept, application/xml;charset=utf-8';

        return config;
    }
};

});

and this

App.config(['$stateProvider', '$httpProvider', '$locationProvider', '$urlRouterProvider', '$ocLazyLoadProvider', function ($stateProvider, $httpProvider, $locationProvider, $urlRouterProvider, $ocLazyLoadProvider) {
$httpProvider.interceptors.push('httpRequestInterceptor');}]);

Now everytime that run i get this error Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.

4
  • What is your backend server? Commented Jun 9, 2017 at 9:06
  • what do you mean? Commented Jun 9, 2017 at 9:07
  • This case occurs because of cross origin reference restrictions of java script. You have to enable cross origin access in your backend application. Let me know your backend technology, then only I can go through it. Commented Jun 9, 2017 at 9:13
  • because backend is not my part, i dont know much about technology. I think that is self-hosted service in a console application. learn.microsoft.com/en-us/dotnet/framework/wcf/samples/… Commented Jun 9, 2017 at 9:21

1 Answer 1

1

I thinks you need to specified Access-Control-Allow-Origin in your server, not in your application angularjs.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.