另一个获得请求的站点是work。但是,当我请求通过localhost进行elasticsearch时,它是不起作用的。
状态代码为:
从json字符串4,0,
readystate=4状态=0
上面结果的javascript代码。
<!DOCTYPE html>
<html>
<body>
<h2>
Create Object from JSON String</h2>
<p id="demo">
</p>
<script>
var url = "http://127.0.0.1:9200/";
document.getElementById("demo").innerHTML = url;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
document.getElementById("demo").innerHTML = xmlhttp.readyState + ", " + xmlhttp.status + ", " + xmlhttp.responseText;
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var response = JSON.parse(xmlhttp.responseText);
document.getElementById("demo").innerHTML = myArr;
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
</script>
</body>
</html>
localhost:9200的工作原理与我搜索时不同,我读到“由于浏览器的原因,您不能通过'localhost'请求”。但是提问者说“我做到了”。所以我想知道我有什么问题。。。
1条答案
按热度按时间eagi6jfj1#
我解决了。我在chrome上安装了那个程序https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi/related