admin管理员组

文章数量:1356780

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?

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?

Share Improve this question asked Mar 3, 2011 at 19:42 FergieFergie 6,2557 gold badges41 silver badges46 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

Solution:

<script type='text/javascript' src='//ajax.googleapis./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 plicated 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.

本文标签: Using JavaScript to read a JSON feed from Solr on a remote server how is it actually doneStack Overflow