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> -->
  </queryResponseWriter>

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 http://40.87.64.225:8983/solr/talks/get?id=76460 timed out
    at fetch-jsonp.js:85