I am trying working off of https://wiki.apache.org/solr/SolJSON tutorial. I 
have put my url for solr in the code, copied from solr admin query result to 
make sure the query should return something.

I try typing in "title:Asian" into text box but when the button is hit, textbox 
just clears and nothing in output spot.

I used the dev tools from [F12] key of browser to check console and see there 
was no errors given there, such as for syntax, so not due to that.

Perhaps I am understanding how the url for query works or should be here? If I 
leave out local host part as shown I just get error for not specifying local 
full path.


<html>
<head>
<title>Solr Ajax Example</title>
<meta charset="UTF-8">
<script language="Javascript">
// derived from http://www.degraeve.com/reference/simple-ajax-example.php
function xmlhttpPost(strURL)
{
    var xmlHttpReq = false;
    var self = this;

    if (window.XMLHttpRequest) { // Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) { // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 
'application/x-www-form-urlencoded');


    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
        }
    };

    var params = getstandardargs().concat(getquerystring());
    var strData = params.join('&');
    self.xmlHttpReq.send(strData);
//document.getElementById("raw").innerHTML = strData;
    return false;
}

function getstandardargs() {
    var params = [
        'wt=json'
        , 'indent=on'
        , 'hl=true'
        ];

    return params;
}
function getquerystring() {
  var form = document.forms['f1'];
  var query = form.query.value;
  qstr = 'q=' + escape(query);
  return qstr;
}

// this function does all the work of parsing the solr response and updating 
the page.
function updatepage(str)
{
  document.getElementById("raw").innerHTML = str;
  var rsp = eval("("+str+")"); // use eval to parse Solr's JSON response
  var html = "<br>numFound=" + rsp.response.numFound;
  var first = rsp.response.docs[0];
  html += "<br>product name=" + first.name;
  var hl = rsp.highlighting[first.id];
  if (hl.name != null) { html += "<br>name highlighted: " + hl.name[0]; }
  if (hl.features != null) { html += "<br>features highligted: " + 
hl.features[0]; }
  document.getElementById("result").innerHTML = html;
}

</script>
</head>
<body>

<form name="f1" 
onsubmit='xmlhttpPost("http://localhost:8983/solr/myCore/select?";)'>
  <p>query: <input name="query" type="text">
  <input value="Go" type="submit"></p>

<div id="result"></div>
<p/><pre>Raw JSON String/output: <div id="raw"></div></pre>

</form>
</body>
</html>



Reply via email to