后台.NET WebApi AngularJS会有跨域问题,jquery 使$.post又正常
请求时添加headers:
app.controller("ppCtrl", function($scope, $http) {
$scope.PostSchoolName = function() {
var BaseUrl = "http://localhost:2996/api/school";
var data = "{'schoolID':'3'}";
$http({
url: BaseUrl,
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: data
})
.success(function(result) {
alert(result);
})
.error(function(res) {
alert("Error")
})
}
})