1

While making a Ajax Request with Json object to "Web Api" using Angular js $http service.It raise CORS Issue,There is no Resolution by adding the following header "Access-Control-Allow-Origin" also,Please suggest me the right solution

Example:

var testmodule = angular.module('testmod', []);

 testmodule.controller('testcontroller', function ($scope, $http) 

{

$scope.Member ={'name':'andrew','age':12,'class':10}

$scope.savedata =function(){

$http({      
            url: "**api url**",
            method: 'POST',
            data: $scope.Member
        }).success(function (data, status) { }).error(function (data, status, headers) { })
}
})
Python Basketball
  • 2,320
  • 3
  • 24
  • 47
Phani Rao
  • 167
  • 1
  • 12

1 Answers1

0

The "Access-Control-Allow-Origin" is a server side issue, you don't need to add any header in angularjs. add the following code to your server side:

("Access-Control-Allow-Origin", "*");   
("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");         
("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, X-Codingpedia");

you can refer to How to enable CORS in AngularJs

Community
  • 1
  • 1
Python Basketball
  • 2,320
  • 3
  • 24
  • 47