View Full Version : ummm, can someone explain this nonsensical "lag" with Ajax content loading?

07-08-2006, 02:05 AM
hey all, i'm having a weird problem, and my situation is a bit complex so i'll just break it down into a psuedo-example which experiences the very same problem. lets say i have a function which loads content into a DIV container called parentBox. the content that gets loaded into parentBox from "main.html" has a DIV inside of it with the ID of "redSquare".

right after i load the main.html file into the parentBox, i'm trying to animate redSquare by sending it to another function. an example:

function initializeMain() {
loadpage('main.html', 'parentBox');

however, beginAnimation fails, saying redSquare is not valid, or does not exist. BUT - if i make it wait for like 2 seconds by having it sit inside of a setTimeout, then it works! this doesn't make any sense to me - VISUALLY, the content loads instantaneously! everything is there! but for some reason, i can't access any of the elements inside it for like 1-2 seconds.. it's like everything loads visually, but the "id" information takes longer to kick in.

now, i don't want to use this crude setTimeout function to wait 2 seconds, because that's extremely arbitrary ... what if, in real life on a server, it takes like 5 seconds for this weird problem to load? 2 seconds might not be enough time.

so first.. why is this happening? secondly, how can i let beginAnimation know when it's ok to start accessing the DIV elements inside of parentBox?

07-08-2006, 05:28 PM
Did you try to put beginAnimation in the callback method, using async mode.