Angularjs 角柱在铬中失效
我有以下几点Angularjs 角柱在铬中失效,angularjs,google-chrome,post,cors,Angularjs,Google Chrome,Post,Cors,我有以下几点 function quoteGridController($scope, $http) { $http.defaults.useXDomain = true; $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded"; delete $http.defaults.headers.common['X-Requested-With']; $http
function quoteGridController($scope, $http) {
$http.defaults.useXDomain = true;
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
delete $http.defaults.headers.common['X-Requested-With'];
$http.post("http://localhost:57048/service/Quote/ReadQuoteForClientId", $.param({ "ClientId": 2 }))
.success(function (data, status) {
alert("Success");
$scope.status = status;
$scope.data = data;
})
.error(function (data, status) {
alert("Error");
$scope.status = status;
$scope.data = data;
});
}
此调用在使用Chrome时失败,但在使用Internet Explorer时成功。据我所知,这是一个CORS问题。有什么方法可以让这个调用在两种浏览器上都工作吗
编辑:Chrome控制台给了我以下信息
function quoteGridController($scope, $http) {
$http.defaults.useXDomain = true;
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
delete $http.defaults.headers.common['X-Requested-With'];
$http.post("http://localhost:57048/service/Quote/ReadQuoteForClientId", $.param({ "ClientId": 2 }))
.success(function (data, status) {
alert("Success");
$scope.status = status;
$scope.data = data;
})
.error(function (data, status) {
alert("Error");
$scope.status = status;
$scope.data = data;
});
无法加载XMLHttpRequest。不
“Access Control Allow Origin”标头出现在请求的服务器上
资源。因此不允许
进入
如上所述,这不是客户端问题。从本地主机运行时,Chrome不允许CORS。一种可能的解决方案是使用自定义域名运行web API,如前所述 然而,我采取了简单的方法,在禁用web安全的情况下启动了Chrome,只是为了测试我的web API代码。从命令提示符下运行此命令
chrome.exe --disable-web-security
然后运行你的应用程序你的chrome控制台说什么?请你也在上面的帖子里贴出来,这不是一个客户独有的问题。您还必须修改服务器发送的头文件(以便在Chrome中允许本地主机上的COR)。给你。