简体   繁体   中英

JSON string too large

I'm using a jQuery plugin that uses a JSON string to suggest its data.

Everything works fine if the JSON string has less than X elements. Above this limit nothing happens, autosuggest fails. I guess it's because there's a kind of parsing limit, but how can I bypass this please ? I have an array of +5000 elements...

Here is my json code :

var SearchTxt = '[{"t":"word one"},{"t":"word two"}, ...]';

Thank you !

$.getJSON() is using the GET method, which is limited by a varying length for each browser . So in your case the returned result apparently exceeds that limit. What you want to do is change

$.getJSON(settings.url,{search:text},function(data){if(data){buildResults(data,text);}
else{$(results).html('').hide();}});

in the source code of the plugin into

$.post(settings.url,{search:text},function(data){if(data){buildResults(data,text);}
else{$(results).html('').hide();}},'json');

which will make it do a POST request instead. Also, make sure to change the reference(s) to the global $_GET array into $_POST if any, in your server-side script.

Ok, so I finally found the source of this problem. There were a parsing error due to the simple quotes... Don't ask me why it only started to happen with a certain number of elements while all quotes where already escaped.

Well, so I changed this :

var SearchTxt = '[{"t":"word one"},{"t":"word two"}, ...]';

to

var SearchTxt = [{"t":"word one"},{"t":"word two"}, ...];

and it worked.

使用JSON没有“解析限制”,任何限制都是由解析JSON请求的服务器设置的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM