Solr and JSONP

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:

  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.

6 thoughts on “Solr and JSONP”

  1. FWIW, you could simple secure your solr installation via IP tables in this case, granting access only to sites within specified IP ranges.

  2. 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.

    url: “”,
    type: “POST”,
    data: { “add”: { “doc”: { “id”: “222222”, “name”: “Ruby on Trails”} } },
    dataType: ‘jsonp’,
    crossDomain: true,
    jsonp: ‘json.wrf’

Comments are closed.