I am trying to get result from URL called by AJAX but even if I am calling the page by the script the success method doesn't show me the result:
<script type="text/javascript">
function searchES() {
var term = $('input[name=q]').val(),
url = "http://localhost:9200/_search",
result = "";
//alert( term );
//alert( url );
$.ajax({
url: url,
type:'get',
data: {q: term},
dataType: 'json',
success: function(response) { $('#result').empty().append("Done is : " + response ); }
});
//event.preventDefault();
}
</script>
By the Firefox Inspect element I can see that the own "get" has been spawned.
11:00:21.900 GET XHR http://localhost:9200/_search?q=*
Can you please advise what I overlooked?
Many thanks in advance, Regards, Reddy
Updated:
So the problem seems to be with CORS. Anyway, I have added the filtering into web.xml of the tomcat webapps application I am working on:
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
and also added parameter
crossDomain:true,
into the ajax code but still getting error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9200/_search?q=*. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
Elastic search has the CORS disabled by default. Hence the problem seems to be on my Tomcat webapps.
Any other ideas?