Firefox Error Parsing JSON with Large String
I have a method that I access remotely using <cfajaxproxy>
. This method returns JSON with a few properties. One of the properties is a string of HTML, and when this string gets really long, Firefox throws an uncaught exception. It works fine in IE9.
The exact size at which the error is thrown is 267,897 bytes, as reported in Firebug for the entire response body. If the response body is 267,896 bytes, it works fine.
Here is the error reported by Firebug
uncaught exception: [Exception... "'SyntaxError: parseJSON' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "JS frame :: chrome://firebug/content/spy.js :: callPageHandler :: line 744" data: no]
http://shop.discountsurgical.com/CFIDE/scripts/ajax/package开发者_JAVA百科/cfajax.js Line 797
Line 797 in cfajax.js tests the response for valid json
if(_492.test(json)){
with _492 defined as this regex
var _492=/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/;
Here is a sample of the response (I've chopped most of it out)
{"content":" 1 2 34 <div id=\"fixedRight\"> <div id=\"toolbox\"> <div class=\"text\">Tools<\/div>
...
<\/script> ","destinationDiv":"main"}
Looks like this is a bug in FireFox 4
http://www.sencha.com/forum/showthread.php?129952-quot-Regular-expression-too-complex-quot-when-using-Mozilla-Firefox-4
and
http://support.mozilla.com/en-US/questions/797123
I had the same error while doing a ColdFusion.JSON.decode(JSONstring). My solution was to use a different JS library. MooTools worked fine for me. JSON.decode(JSONstring). Just make sure to remove the JSON prefix that coldfusion appends at the begining of the string. (if it applies to you)
Alternatively you can edit cfajax.js to remove the test. After all you should be returning valid JSON for your app to work in the first place and if you do need to validate your json string you can do that serverside...
I hope this helps.
Does the error occur with Firebug turned off? Someone else on SO had an odd error and it was caused by Firebug.
精彩评论