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) { })
}
})
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
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.