tags:

views:

61

answers:

3

Hi,

To enable a go back function with an ajax div i have create these simple functions and i was wondering how much data a .js global variable can hold??

    var dataAfterSearch; //global variable which holds our search results

function goBackAfterSearch() {
    /**
    *   function which displays the previous state
    *
    **/
    $.ajaxSetup ({
        cache: false
    });
    //alert("Previous Search" +dataAfterSearch);
    $('#result').html(dataAfterSearch);
     paginateIt();
}
function setDataAfterSearch(data)
{   
    /**
    * function to set the global dataAfterSearch
    *
    **/
    dataAfterSearch = data;
}

kind regards

A: 

Global variables aren't any different than non-global variables in what and how much they can hold. The specifications don't mention a limitation on string length (a string being what will be returned by AJAX), so I think it's implementation dependent.

I found this discussion on bytes.com where they mention some limitations they reached amongst different browsers.

Bob
tx, although i was hoping it was unlimited. Might need to rethink my solution :(
alex
Well, all data is going to be limited in some way. Computers don't have unlimited amounts of memory or even hard drive space. Just how much data are you expecting? What are you trying to accomplish?
Bob
i am developing a multi filter search on list of jobs. The result are shown without page refresh (jQuery/ajax) and i needed a go-to-previous-page solution when an user is on a job detailed page. So let's say a list of 2000 jobs/rows can this be stored in a global variable?? see a simplyfied example: bldd.nl/stackoverflow/pagination/index2.php
alex
It depends on how big each list item is, but 2000 should be fine if it's an object. I wouldn't store all information either. I'd simply keep the minimum needed and call AJAX when more information needs to be displayed. For instance, if there's a job ID that you use to pull down data from the server just keep that ID and call AJAX when needed
Bob
@bob, 1/ how do i make sure it's an object?? 2/ I think you might have misunderstood my use of the global. I am using the global as a previous state just to enable a go back link. 3/Do you know how i can attach my function goBackAfterSearch() to the browser back button??regards
alex
A: 

a variable in javascript can hold an object or a string. An object is an unlimited data structure. Strings are limited only by the implementation (as Bob said), and shouldn't be a constraint for you.

PanCrit
@PanCrit, Strings are limited only by the implementation could you explain this to me/give me an example? (if you can find the time). I am not sure if my functions have these limitations
alex
A: 

There is no limit, the maximum size is browser/implementation specific.

You can test the limit by executing a script like this:

var str = "";
var sizeCount = 0;
while( true ) {
   str += "a";
   if( ++sizeCount >= 1048576 ) { // Show an alert for every MB
      alert( str.length );
      sizeCount = 0;
   }
}

I get an error in Chrome around 26MB.

Ryan Emerle