You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Sunil Dash <su...@gmail.com> on 2020/10/01 09:55:34 UTC

Solr client in JavaScript

This is my javascript code ,from where I am calling solr ,which has a
loaded nutch core (index).
My java script client ( runs on TOMCAT server) and Solr
server are on the same machine (10.21.6.100) . May be due to cross
domain references issues OR something is missing I don't know.
I expected Response from Solr server (search result) as raw JASON
object. Kindly help me fix it.Thanks in advance .

Rgds
Sunil Kumar


<html>
<head>  <title>Solr Search </title> </head>
<body>
    <script language="Javascript">
    function search()
    {
     var xmlHttpReq =false;
     var  xmlHttpClient=this;

     var hostURL='http://10.21.6.100:8983/solr/nutch/select';
     var querystring=document.getElementById("querystring").value;
     qstr='q='+escape(querystring)+"&fl=content";

     if(window.XMLHttpRequest){  xmlHttpClient.xmlHttpReq=new
XMLHttpRequest(); }

     xmlHttpClient.xmlHttpReq.open('POST',hostURL,true);


xmlHttpClient.xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

     xmlHttpClient.xmlHttpReq.send(qstr);

     xmlHttpClient.xmlHttpReq.onreadystatechange=function()
      {
      if(xmlHttpClient.xmlHttpReq.readyState ==4 )
            { showresponse(xmlHttpClient.xmlHttpReq.responseText);}
      }

    }

     function showResponse(str)
    {
       document.getElementById("responsestring").innerHTML=str;
    }

    </script>

     <h3>Solr Search [ From Javascript ]</h3>
    <div align='center'>
     <input id="querystring" name="querystring" type="text"
placeholder="Search here..">
     <input value="search" type="button" onClick='search();'>
     <p>
       <div id="result"> </div>
       <div id="responsestring"> </div>
     </div>
</body>

Re: Solr client in JavaScript

Posted by Shawn Heisey <ap...@elyograg.org>.
On 10/1/2020 3:55 AM, Sunil Dash wrote:
> This is my javascript code ,from where I am calling solr ,which has a
> loaded nutch core (index).
> My java script client ( runs on TOMCAT server) and Solr
> server are on the same machine (10.21.6.100) . May be due to cross
> domain references issues OR something is missing I don't know.
> I expected Response from Solr server (search result) as raw JASON
> object. Kindly help me fix it.Thanks in advance .

As far as I can tell, your message doesn't tell us what the problem is. 
So I'm having a hard time coming up with a useful response.

If the problem is that the response isn't JSON, then either you need to 
tell Solr that you want JSON, or run a new enough version that the 
default response format *IS* JSON.  I do not recall which version we 
changed the default from XML to JSON.

One thing you should be aware of ... if the javascript is running in the 
end user's browser, then the end user has direct access to your Solr 
install.  That is a bad idea.

Thanks,
Shawn