【发布时间】:2016-06-29 23:00:31
【问题描述】:
我正在使用 angularjs 制作一个网络应用程序。我正在对 elasticsearch api 提出请求。这是代码:
app.controller('usersDatas', function($scope, $http){
$http.post("http://192.168.6.55:9200/userdata/_search", {headers : { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
data: "{ 'query': { 'query_string': { 'query': 'png' } } }"
// Access-Control-Allow-Origin: true
}).success(function(data){
console.log(data);
});
});
这是我遇到的错误:
XMLHttpRequest cannot load http://192.168.6.55:9200/userdata/_search. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
我已经添加了这个:
http.cors:
enable: true
allow-origin: /https?:/\/\/localhost(:[0-9]+)?/
到我的弹性搜索 (/etc/elasticsearch/elasticesarch.yml) 配置。我不知道问题是来自elasticsearch还是来自angularjs。 我该如何解决这个问题? 谢谢。
【问题讨论】:
-
你用的是windows还是linux系统还是ios??
-
我使用的是 ubuntu 16.04
标签: angularjs elasticsearch cross-domain