JS parsing error

97 views
Skip to first unread message

bimargulies

unread,
May 5, 2011, 9:17:06 PM5/5/11
to ajax-solr
I've set up a cut-down version of the reuters demo with jquery 1.5.2
and a snapshot of Solr 4.0.

Something Nasty happens when the json comes back from solr, and what
appears in the Chrome javascript console is:

Uncaught SyntaxError: Unexpected token ILLEGAL.

Does this ring any bells?

bimargulies

unread,
May 5, 2011, 9:19:00 PM5/5/11
to ajax-solr
More info from chrome. Note the non-javascript response type at the
end ...

Request URL:http://localhost:9167/solr/select?q=*
%3A*&json.nl=map&group=true&group.field=bt.nearDupCluster&group.main=true&wt=json&json.wrf=jQuery15208900942071340978_1304644496207&_=1304644496301
Request Method:GET
Status Code:200 OK
Request Headers
Accept:text/javascript, application/javascript, application/
ecmascript, application/x-ecmascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:localhost:9167
Referer:http://localhost:9167/lsh/solr-query.jsp
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/
534.24 (KHTML, like Gecko) Chrome/11.0.696.57 Safari/534.24
X-Requested-With:XMLHttpRequest
Query String Parameters
q:*:*
json.nl:map
group:true
group.field:bt.nearDupCluster
group.main:true
wt:json
json.wrf:jQuery15208900942071340978_1304644496207
_:1304644496301
Response Headers
Content-Type:text/plain;charset=UTF-8
Date:Fri, 06 May 2011 01:14:56 GMT
ETag:"NThmN2UzNDNmNDgwMDAwMFNvbHI="
Last-Modified:Fri, 06 May 2011 01:12:21 GMT
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked

bimargulies

unread,
May 5, 2011, 9:33:13 PM5/5/11
to ajax-solr
One more:Here's the beginning of the actual response from Solr. Looks
like jsonp to me?



responseText:
"jQuery152018983175908215344_1304645404800({"responseHeader":{"status":
0,"QTime":16,"params":{"json.w…"

James McKinney

unread,
May 5, 2011, 9:56:42 PM5/5/11
to ajax...@googlegroups.com
Yes, JSONP is expected. What happens when you run the JSONP JavaScript snippet? Does it cause the syntax error?

Benson Margulies

unread,
May 5, 2011, 10:11:05 PM5/5/11
to ajax...@googlegroups.com
JsonLint thinks it's fine. I haven't fed it to rhino or some other
interpreter yet.

I think I had better switch to firefox first and see if it agrees with chrome.

Benson Margulies

unread,
May 5, 2011, 10:33:27 PM5/5/11
to ajax...@googlegroups.com
Debugging in FF, it looks like the return content-type of text may be
eliciting wrong behavior in jquery, as it never even tries to evaluate
the string.

James McKinney

unread,
May 5, 2011, 10:52:12 PM5/5/11
to ajax...@googlegroups.com
Not sure why Solr would return a content-type that would not be understood by jQuery. I didn't think jQuery cared about the content-type if it was told it would receive JSONP content... Could this thread help? http://groups.google.com/group/ajax-solr/browse_thread/thread/38de4bbb54e0e5d7?pli=1

Benson Margulies

unread,
May 6, 2011, 6:53:39 AM5/6/11
to ajax...@googlegroups.com
I've traced through the code in jquery. It is trying to adapt to
different returned content types.

This raises three questions: 1) why is this new version of solr
returning 'text'? 2) Why are you asking for jsonp when plain json
should be fine, and 3) is there a parameter to jQuery.ajax() that
would force it to interpret the results as jsonp? I'm investigating.

Benson Margulies

unread,
May 6, 2011, 7:34:25 AM5/6/11
to ajax...@googlegroups.com
If I take out the json.wrf and thus use plain json, not jsonp, all is well.

James McKinney

unread,
May 6, 2011, 10:19:57 AM5/6/11
to ajax...@googlegroups.com
Cool, thanks for reporting back.

Plain JSON may not work for other users, due to cross-domain policies implemented by browsers.

Benson Margulies

unread,
May 6, 2011, 10:40:47 AM5/6/11
to ajax...@googlegroups.com
I think I'm going to offer you a patch with an alternative manager.
Reply all
Reply to author
Forward
0 new messages