【发布时间】:2016-08-15 18:51:03
【问题描述】:
当我尝试从本地应用程序发出 POST 请求时出现以下错误:
XMLHttpRequest cannot load https://www.xxx..yy/json/orders. Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values '*, http://localhost:9000', but only one is allowed. Origin 'http://localhost:9000' is therefore not allowed access.
这是我的应用程序结构简介:
ctrl:
.controller('myCtrl', function ($scope,$http) {
var urlBase = "https://xxx/json/";
console.log("Hello...");
$scope.startDirectTransaction = function() {
console.log("startDirectTransaction form...");
$http({method: 'POST', url: urlBase + 'orders', headers: {
'api_key': 'xxx'}
}).then(function(response){
$scope.related = response.data;
console.log("Success!");
});
};
app:
<!-- begin snippet: js hide: false -->
【问题讨论】:
-
你是否在你的 chrome 中安装了 CROS 扩展
-
您是否在服务器端代码上设置了 CORS 标头?进行跨域请求时出现 CORS 错误,我只看到 localhost?
-
你的服务器 IP 必须是
whitelistedbyxxx -
我无法控制服务器端代码。所以需要一个解决方法。
标签: javascript angularjs https http-headers cors