Search code examples
javascriptjsonsolrjsonp

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


I cannot seem to get this to work, I have heard rumours that you actually need a jsonp object.

Does anybody have a code snippet for reading a JSON feed from Solr on a remote server?


Solution

  • 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