4

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 !

SuN
  • 1,036
  • 2
  • 12
  • 25

3 Answers3

3

$.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.

Community
  • 1
  • 1
inhan
  • 7,394
  • 2
  • 24
  • 35
  • thanks inha, but I'm really new to json, and I don't know where to fix this in the [plugin code](http://tomcoote.co.uk/wp-content/CodeBank/Demos/JSONSuggestBox/jquery.jsonSuggest-dev.js). I tried several things but nothing works. – SuN Nov 19 '12 at 15:01
  • You can use CTRL+F to find somehing in an open document and CTRL+V to paste something you have already copied. – inhan Nov 20 '12 at 15:49
1

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.

SuN
  • 1,036
  • 2
  • 12
  • 25
0

There's no "parsing limit" with JSON, any limitation is set by the server parsing the JSON request.

PhilTrep
  • 1,521
  • 1
  • 10
  • 23
  • ok, but how can I check this parameter and how to fix this ? My array works with 2000-2500 elements, but I need to add the double – SuN Nov 16 '12 at 16:23
  • change max_post_size in php.ini to change the maximum post size – PhilTrep Jan 15 '13 at 14:49