Using JavaScript to read a JSON feed from Solr on a remote server- how is it actually done? Using JavaScript to read a JSON feed from Solr on a remote server- how is it actually done? json json

Using JavaScript to read a JSON feed from Solr on a remote server- how is it actually done?


Solution:

<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js'></script><script type='text/javascript'>$.getJSON("http://remotehost:8080/solr/select/?q=jaberwocky&wt=json&json.wrf=?", function(result){ alert("hello" + result.response.docs[0].name);});</script>

The complicated bit is understanding nameless callbacks in this case json.wrf=?. Basically if you add json.wrf=? to your solr url it will start working

JSONP appears to be a red herring in this instance


The first result for "solr jsonp" gives Solr and JSONP. Does that work for you?

EDIT: To show this is just JSONP, and using the question mark replacement is optional (but convenient), you can just use getScript and your own callback:

function my_callback(response){}$.getScript("http://remotehost:8080/solr/select/?q=jaberwocky&wt=json&json.wrf=my_callback");

You don't even need jQuery. You could do the same thing by manually creating and appending a <script> element.


You can use JSONP for jQuery for jQuery JSONP requests. You can use it easily to read data from remote server.