HighDots Forums  

Timing/Event issue regarding data being loaded from xml

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Timing/Event issue regarding data being loaded from xml in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ezmiller
 
Posts: n/a

Default Timing/Event issue regarding data being loaded from xml - 01-08-2006 , 05:45 PM






Hi,
I have some code on a page that loads data from several xml documents
into a series of arrays.
The function that loads the data from the xml files into the arrays is
called from the document body's onload event. The problem I am running
into is that in some cases the data has not yet been loaded into the
arrays (i.e. the arrays are still undefined) when other functions are
called which process the data in those arrays for display on the web
page.

So what I am wondering is whether anyone has any ideas for a solution
that would allow me to call those functions that process the data in
the arrays only once all the arrays have been created.

Best,
Ezmiller


Reply With Quote
  #2  
Old   
Wayne Dobson
 
Posts: n/a

Default Re: Timing/Event issue regarding data being loaded from xml - 01-09-2006 , 04:48 AM






"ezmiller" <ethanzanemiller (AT) gmail (DOT) com> wrote

Quote:
Hi,
I have some code on a page that loads data from several xml documents
into a series of arrays.
The function that loads the data from the xml files into the arrays is
called from the document body's onload event. The problem I am running
into is that in some cases the data has not yet been loaded into the
arrays (i.e. the arrays are still undefined) when other functions are
called which process the data in those arrays for display on the web
page.

So what I am wondering is whether anyone has any ideas for a solution
that would allow me to call those functions that process the data in
the arrays only once all the arrays have been created.
I'm definately missing something. I don't understand why it is that you do
not simply ensure that all of the arrays are defined, before you start
trying to process the data within them.

--
Wayne
"Aka Dobbie the House Elf."




Reply With Quote
  #3  
Old   
ezmiller
 
Posts: n/a

Default Re: Timing/Event issue regarding data being loaded from xml - 01-09-2006 , 06:35 AM



Ok...but I dont' know how to accomplish that...how can you make it wait
until all the arrays are defined?


Reply With Quote
  #4  
Old   
Wayne Dobson
 
Posts: n/a

Default Re: Timing/Event issue regarding data being loaded from xml - 01-09-2006 , 07:57 AM



"ezmiller" <ethanzanemiller (AT) gmail (DOT) com> wrote

Quote:
Ok...but I dont' know how to accomplish that...how can you make it wait
until all the arrays are defined?
Maybe a code example would help clarify where the problem is.

--
Wayne
"Aka Dobbie the House Elf."




Reply With Quote
  #5  
Old   
ezmiller
 
Posts: n/a

Default Re: Timing/Event issue regarding data being loaded from xml - 01-09-2006 , 12:21 PM



Ok, there is a lot of code so I will include some of it with
explanation.

I have four arrays: users, projects, activities, logEntries.

The arrays are loaded in two steps. The first is a function loadXML
that loads the xml file and
then calls a handler. Here it is:

function loadXML(url, handler) {
//alert("loadXML called, url: " + url);
// Check for DOM level 2 implementation
var xmldoc;
if (document.implementation &&
document.implementation.createDocument) {
xmldoc = document.implementation.createDocument("","",null) ;

// Set the onload handler to call the supplied function **
xmldoc.onload = function() { handler(xmldoc); }
xmldoc.load(url);

// Otherwise try MS IE-specific ActiveX model
} else if (window.ActiveXObject) {
xmldoc = new ActiveXObject("Microsoft.XMLDOM");

// Set the state change handler to
// call the supplied function
xmldoc.onreadystatechange = function() {
if (xmldoc.readyState == 4) handler(xmldoc); }
xmldoc.load(url);
}
}

And here is an example of the handler that loads the data from the xml
into the users
array. The function creates a User objects (which I defined) and puts
them into the array.

function loadUsers(xmlDoc)
{
users = new Array();
var xmlUsers = xmlDoc.getElementsByTagName("user");
var id, f, l, h, m;
for (var i=0; i<xmlUsers.length; i++) {
id = xmlUsers[i].getElementsByTagName("user_id")[0].text;
f = xmlUsers[i].getElementsByTagName("first_name")[0].text;
l = xmlUsers[i].getElementsByTagName("last_name")[0].text;
h =
parseFloat(xmlUsers[i].getElementsByTagName("hourly_rate")[0].text);
m = xmlUsers[i].getElementsByTagName("is_manager")[0].text;
users[i] = new User(id,f,l,h,m);
}
xmlDoc = null;
setCurrentUser();
}

The problem I am having is with a function called writeLogTable which
uses data from all four
arrays to write a table to the page. I want this function to be called
once when the page loads, but when
I run that function say from the window.onload event or document onload
event or even in code placed
after the html, I run into the problem that one or several of the
arrays has not yet been filled. But what I can't
figure out is how to call this function immediatley when the page is
opened but after all the arrays have been
loaded.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.