473,322 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

cache dom object into js associative array object

2
hi all

i've got this application where a user selects tabs on the page, which then loads a different section onto another section of the page

we currently have it working using ajax, but we would like it to cache the current object before loading the next one
and then, if it gets selected again, it can be loaded from the cache if it exists, otherwise load it from ajax

our code works in firefox, but in ie, the cached object becomes empty (not null, or undefined), we are storing it in an associative array object, and when we alert it, it is just nothing

we're using prototype, testing in firefox 1.5 and ie6

[php]
// the assoc array used as the cache
var cachedThemeTabContents = new Object();

function updateThemeTabContent(themeId) {
// get the name of the current theme, this is a string used as the assoc array key
var theme = getTheme();
// get the dom object that is currently loaded
var element = $('theme-tab-content');

// cache the current contents of the theme tab div
//cachedThemeTabContents[theme] = element.childNodes.item(0);
// set the theme to the newly selected theme
setTheme(themeId);

// check to see if the theme is cached, if it is, simply replace the current
// node with the cached one and return
if (cachedThemeTabContents[themeId] != null) {
var children = element.childNodes;
element.removeChild(children.item(0));
element.appendChild(cachedThemeTabContents[themeId]);

return;
}

// otherwise update it via ajax
// just a function to load the new theme into the element using ajax/prototype
//
// #############
// this is where the problem occurs in ie
// #############
var params = 'cmd=updateThemeTabContent'
+ '&theme=' + themeId
+ '&domain=' + getDomain();
startLoading();
asyncUpdate('theme-tab-content', params,
function(originalRequest) {
endLoading();
});
}


function asyncUpdate(destId, params, oncomplete) {
var url = '/index.php';
new Ajax.Updater(
destId,
url,
{
method: 'post',
parameters: params,
onComplete: function(originalRequest) {
if (oncomplete != null) {
oncomplete.call(this, originalRequest);
}
},
onFailure: function(originalRequest) {
alert('Error performing request, please try again later');
}
});
}
[/php]
basically, after the new element has been loaded from ajax, the previous ones are empty
i've used alerts to debug, and the innerHTML exists up until that ajax call at the bottom, after it, they will just be '', so they exist, but have no value

any ideas
thanks
dave
Oct 2 '06 #1
2 3154
iam_clint
1,208 Expert 1GB
You may have to store the information in hidden divs.
Sep 8 '08 #2
rnd me
427 Expert 256MB
without seeing the function setTheme, i can tell you that if you set an object property to another object (like a div tag for instance), it creates a reference to that tag.

it sound like you want to pass it by value instead.

since all js objects are linked (not copied), you will have to save a primitive, like a string of the .innerHTML, use prototype's .clone if you want to copy a js object, or set the value stored in your cached object's respective key using .cloneNode(true) rather than a direct assignment to the element.

there is no need for hidden divs...
Sep 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Stefan Richter | last post by:
Hi, I want to create an associative Array with a PHP variable (article ID) as Key and another associative array as it's value. How do I instanciate it, how can I fill it? I want something...
1
by: Robert Oschler | last post by:
With PHP 4, is there a way to convert an associative array to an object? For example, suppose I have the following arrays inside a nested associative array ($nestedAA): $AA1 = 'fieldValue1'; ...
6
by: mark4asp | last post by:
Suppose I have the following code. It functions to randomly select a city based upon the probabilities given by the key differences in the associative array. . Eg. because the key difference...
11
by: JehanNYNJ | last post by:
Is it possible to have an Object as the key for an Associative array like in the following example.... function Obj(var1, var2) { this.var1 = var1; this.var1 = var1;
16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
11
by: Bosconian | last post by:
I'm trying to output the contents of an array of associative arrays in JavaScript. I'm looking for an equivalent of foreach in PHP. Example: var games = new Array(); var teams = new...
14
by: julie.siebel | last post by:
I've been wrestling with a really complex page. All the data is drawn down via SQL, the page is built via VBScript, and then controlled through javascript. It's a page for a travel company that...
1
by: SmoothFloyd13 | last post by:
Hi, My group is working on a project involving implementing a set-associative cache for various cache sizes, block sizes, and associativities. We wrote code (C code) for an array, initialized it,...
0
by: Hypnotik | last post by:
My program is to simulate cache memory. I read in the info from 2 external files, 1) access 2) data in memory. When I read the information in I display the info...and it is all correct. However...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.