Need to send an Ajax request to a Solr server that’s on a different domain? You will, of course, need to use JSONP instead of an ordinary JSON request, due to JavaScript’s cross-domain security restrictions. To get a properly padded response from Solr, add the json.wrf
parameter to your query string, giving it the name of your callback function. In jQuery:
jQuery.ajax({ url: mySolrUrl, data: myQueryParameters, success: mySuccessCallback, dataType: 'jsonp', jsonp: 'json.wrf' });
Of course, for this to work the Solr server you’re accessing needs to be publicly accessible, which probably isn’t ideal for security.
FWIW, you could simple secure your solr installation via IP tables in this case, granting access only to sites within specified IP ranges.
Very thanks your simple case. It helps me.
Can you please also give an example of indexing solr using jsonp.
I am trying in similar way, but it fails.
The code below doesn’t work.
$.ajax({
url: “http://192.168.10.113:8080/solr/update/json?commit=true”,
type: “POST”,
data: { “add”: { “doc”: { “id”: “222222”, “name”: “Ruby on Trails”} } },
dataType: ‘jsonp’,
crossDomain: true,
jsonp: ‘json.wrf’
});
I love you. Thanks you.
*thank you
You made my day. My weekend, actually. Thanks!