Fixing error talking to Solr: “Unexpected token :” over JSONP

If you try to access solr with JSONP, you can get this error: “Fixing error talking to Solr: “Unexpected token :” over JSONP”.

The issue is that the Content-Type header is text/plain, rather than application/json.

The solution is to go into your solrconfig.json. comment out the section in queryResponseWriter, so it looks like this:

You also need to make sure these parameters are on the URL: wt=json&json.wrf=callback.

  <queryResponseWriter name="json" class="solr.JSONResponseWriter">
    <!-- <str name="content-type">text/plain; charset=UTF-8</str> -->

For the record, here is the error I got/:

Uncaught SyntaxError: Unexpected token :
VM1777:1 XHR finished loading: GET "http://localhost:3000/sockjs-node/info?t=1507602202275".
(anonymous) @ VM1777:1
./node_modules/sockjs-client/lib/transport/browser/abstract-xhr.js.AbstractXHRObject._start @ abstract-xhr.js:132
(anonymous) @ abstract-xhr.js:21
setTimeout (async)
AbstractXHRObject @ abstract-xhr.js:20
XHRLocalObject @ xhr-local.js:8
InfoAjax @ info-ajax.js:19
./node_modules/sockjs-client/lib/info-receiver.js.InfoReceiver._getReceiver @ info-receiver.js:36
./node_modules/sockjs-client/lib/info-receiver.js.InfoReceiver.doXhr @ info-receiver.js:56
(anonymous) @ info-receiver.js:25
setTimeout (async)
InfoReceiver @ info-receiver.js:24
SockJS @ main.js:121
./node_modules/react-dev-utils/webpackHotDevClient.js @ webpackHotDevClient.js:47
__webpack_require__ @ bootstrap a5da7f792035a34edb8e:669
fn @ bootstrap a5da7f792035a34edb8e:87
0 @ registerServiceWorker.ts:114
__webpack_require__ @ bootstrap a5da7f792035a34edb8e:669
(anonymous) @ bootstrap a5da7f792035a34edb8e:715
(anonymous) @ bundle.js:719
fetch-jsonp.js:85 Uncaught (in promise) Error: JSONP request to timed out
    at fetch-jsonp.js:85

Interested in Solr? I send out weekly, personalized emails with articles and conference talks. Click here to see an example and subscribe.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *