S
steve.chambers
I'm sure this q must have been asked before but I'm really struggling
to find the answer anywhere so have finally given up and will consult
the usenet community - hopefully there's someone out there who's seen
it all before and can help me out! I have a webpage which needs to
make some function calls after the page has loaded - won't go into
details surfice to say here is a code fragment:
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload == 'function') {
window.onload = function() {
oldonload();
func();
}
} else {
window.onload = func;
}
}
addLoadEvent(myFunction1);
addLoadEvent(myFunction2);
addLoadEvent(myFunction3);
...etc...
My problem is that some of these myFunction#s include AJAX calls but
the calls depend on each other in such a way that myFunction2 will not
work unless myFunction1 has completed. So what is the "nicest" way to
make sure of this? I've considered putting a hidden element in the
HTML and then changing it at the end of each function call and have
the onchange event trigger the next function call. But this seems very
hacky and overcomplicated - surely there must be a simpler and better
way....?
Cheers for any advice / suggestions,
Steve
to find the answer anywhere so have finally given up and will consult
the usenet community - hopefully there's someone out there who's seen
it all before and can help me out! I have a webpage which needs to
make some function calls after the page has loaded - won't go into
details surfice to say here is a code fragment:
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload == 'function') {
window.onload = function() {
oldonload();
func();
}
} else {
window.onload = func;
}
}
addLoadEvent(myFunction1);
addLoadEvent(myFunction2);
addLoadEvent(myFunction3);
...etc...
My problem is that some of these myFunction#s include AJAX calls but
the calls depend on each other in such a way that myFunction2 will not
work unless myFunction1 has completed. So what is the "nicest" way to
make sure of this? I've considered putting a hidden element in the
HTML and then changing it at the end of each function call and have
the onchange event trigger the next function call. But this seems very
hacky and overcomplicated - surely there must be a simpler and better
way....?
Cheers for any advice / suggestions,
Steve