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 Responses to Solr and JSONP

  1. unexpand says:

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

  2. guest says:

    Very thanks your simple case. It helps me.

  3. Amit says:

    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’

  4. Andrew says:

    I love you. Thanks you.

  5. Andrew says:

    *thank you

  6. Denis says:

    You made my day. My weekend, actually. Thanks!