Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角柱在铬中失效_Angularjs_Google Chrome_Post_Cors - Fatal编程技术网

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)。给你。