跨域异常:XMLHttpRequest cannot load ''. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' ' is therefore not allowed access.
做ES搜索的时候出现了以上问题,百度了一些方法,都不能解决,其中一个方法是在ajax内加入
dataType:"jsonp,虽能解决跨域问题,但是却出现了请求的数据不能识别,如下异常:
"type": "illegal_argument_exception",
"reason": "request [/books/book/1] contains unrecognized parameters: [_], [callback]"
最后请教一个大牛,顺利解决了,在ES的conf文件夹下的elasticsearch.yml文件内最下面加入下面两句话:
http.cors.enabled: true
http.cors.allow-origin: /http?://*.*.*.*(:[0-9]+)?/