Javascript Variable Limitation?

Hi, there seems to be some sort of problem on both my Linodes where the Javascript functions are not working because there is a limit in the variable resources. It seems that they can't accept more than 4k bytes in data. This is happening with the AJAX functions, where if the responses are bigger than 4k Bytes in data, nothing will load. Does anyone have any idea how I can fix this? Thank you so much! :)

5 Replies

What does your browser's development tools have to say?

The developing tools in Chrome don't retrieve any error from the Javascript. But the Jquery AJAX function launches the error function because it "doesn't receive" any data because the variable seems to get the maximum amount, if the received data is less than 4K Bytes then it works as it should work.

Here is the code I'm using with a Wordpress slider:

var currentActiveSlide = '';

function loadContent( e) {

currentActiveSlide = e;

jQuery.post(template_url + '/ajax.php', { 'action': 'slideContent', 'rel': e.attr('rel') }, function(data) {

e.html(data.substring(0, data.length - 1));

});

}

Clarification of what Bacon is saying, javascript is typically client-side, and as such has nothing to do with your Linode.

My programmer said to say this: "Yeah but seems to be a limit in the data that is retrieved to the javascript requests. Seems that if the data to be retrieved is more than 4k Bytes then it fails."

SurferJon,

Your Linode doesn't have any real limit to what it can send. I know that cookies have a size limit (I think it's 4k but can be set up to 8k in the Apache config IIRC).

You should probably be asking a jquery (or general javascript) forum about this limit. I know some browsers (which may be adhering to industry standards) have a 4k limit on what DOM objects can hold.

If you really need to return more than 4k of data from an ajax request maybe you can split it up into multiple segments that are assigned to array elements upon receiving your responseText.

  • Have your server code split the response into segments that are a maximum length of 4k and use URL friendly separator characters between the segments (eg, '%|%').

  • Split your responseText into an array (eg, var results = xmlHttp.responseText.split('%|%'); ) and pass the results array to your callback routine.

  • Your callback routine can walk the array and append the segments to the target html element (if that's what you're doing).

If your results are encoded in base64 then the above process won't work as described. You'd have to split your results at the server into segments that are less than 3k each and have them base64 encoded before assembling your large response (separated by your characters of choice). You'd then have to have each array element decoded before using it.

Keep in mind that segmenting your server response into logical segments is the best approach (even if they are well below the 4k limit).

MSJ

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct