JSON string is too big

I am using a jQuery plugin that uses a JSON string to offer my data.

Everything works fine if the JSON string has less than X elements. Above this limit, nothing happens, autocompletion is not performed. I think this is because there is some kind of syntactic divorce, but how can I get around this, please? I have an array of +5000 elements ...

Here is my json code:

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

Thanks!

+4
source share
3 answers

Ok, so I finally found the source of this problem. There was a parsing error due to simple quotes ... Do not ask me why this is just starting to happen with a certain number of elements, while all the quotes that have already escaped.

So, I changed this:

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

to

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

and he worked.

+1
source

$.getJSON() uses the GET method, which is limited by the varying length for each browser . Therefore, in your case, the returned result obviously exceeds this 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 in

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

which will force it to execute a POST request. Also, be sure to change the reference to the global $_GET array to $_POST , if any, on the server side script.

+3
source

There is no "parsing limit" in JSON, any restriction is set by the server processing the JSON request.

0
source

Source: https://habr.com/ru/post/1446488/


All Articles