Answer the question
In order to leave comments, you need to log in
How to use ElasticSearch.js in Chrome browser?
The system (Windows 10 x64) has ElasticSearch 6.2.4 installed.
There is the following html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TestES</title>
<script>
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}
function testES(){
var url = 'http://localhost:9200/';
// var url = 'http://html5rocks-cors.s3-website-us-east-1.amazonaws.com/index.html';
var xhr = createCORSRequest('GET', url);
if (!xhr) {
throw new Error('CORS not supported');
} else {
xhr.onload = function() {
var responseText = xhr.responseText;
console.log('response: ' + responseText);
};
xhr.onerror = function() {
console.log('There was an error!');
};
xhr.send();
}
}
</script>
</head>
<body>
<input type="button" onclick="testES();" value="Click me">
<div id="result"></div>
</body>
</html>
Error: Access to XMLHttpRequest at 'http://localhost:9200/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
There was an error!
Warning: Cross-Origin Read Blocking (CORB) blocked cross-origin response http://localhost:9200/ with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question