Connecting Tech Pros Worldwide Help | Site Map

ReadyState issues

MAB
Guest
 
Posts: n/a
#1: Mar 1 '07
I have the following function:

function doStuff(str) {
var DataSite="test1a.asp?q="+str;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = DataSite;
document.getElementsByTagName('head')[0].appendChild(script);
var x = doMoreStuff();
}

The function loads an asp page into memory. I am looking for a cross
browser solution to test to see if the page is fully loaded before
doMoreStuff is called. Can anyone offer some code or point me in the
right direction? Thanks.

Mister Joe
Guest
 
Posts: n/a
#2: Mar 2 '07

re: ReadyState issues


On Mar 1, 6:00 pm, "MAB" <mbeck...@gmail.comwrote:
Quote:
I have the following function:
>
function doStuff(str) {
var DataSite="test1a.asp?q="+str;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = DataSite;
document.getElementsByTagName('head')[0].appendChild(script);
var x = doMoreStuff();
}
>
The function loads an asp page into memory. I am looking for a cross
browser solution to test to see if the page is fully loaded before
doMoreStuff is called. Can anyone offer some code or point me in the
right direction? Thanks.

I'm guessing that either doMoreStuff or something that doeMoreStuff
needs is in the script you are trying to load. You may want to try
using a try catch statement. That way if you get an exception b/c you
are trying to access an element that has not been created (or a
similar exception) in the catch you can set the timeout for 2 seconds
(or whatever you think is best).

MAB
Guest
 
Posts: n/a
#3: Mar 2 '07

re: ReadyState issues


On Mar 2, 9:56 am, "Mister Joe" <mrjoefri...@gmail.comwrote:
Quote:
On Mar 1, 6:00 pm, "MAB" <mbeck...@gmail.comwrote:
>
Quote:
I have the following function:
>
Quote:
function doStuff(str) {
var DataSite="test1a.asp?q="+str;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = DataSite;
document.getElementsByTagName('head')[0].appendChild(script);
var x = doMoreStuff();
}
>
Quote:
The function loads an asp page into memory. I am looking for a cross
browser solution to test to see if the page is fully loaded before
doMoreStuff is called. Can anyone offer some code or point me in the
right direction? Thanks.
>
I'm guessing that either doMoreStuff or something that doeMoreStuff
needs is in the script you are trying to load. You may want to try
using a try catch statement. That way if you get an exception b/c you
are trying to access an element that has not been created (or a
similar exception) in the catch you can set the timeout for 2 seconds
(or whatever you think is best).
Thanks for the response. the doMoreStuff function process the data
from the page that was loaded. Unfortunately, it tries to do it
before the page finishes loading. As a result, I get no data the
first time it is run and I remain one iteration behind the data
generation.

I would prefer not to use a timeout as I will simpley have to guess
how long it will take to run.

Other ideas?

Tom Cole
Guest
 
Posts: n/a
#4: Mar 2 '07

re: ReadyState issues


On Mar 2, 1:00 pm, "MAB" <mbeck...@gmail.comwrote:
Quote:
On Mar 2, 9:56 am, "Mister Joe" <mrjoefri...@gmail.comwrote:
>
>
>
>
>
Quote:
On Mar 1, 6:00 pm, "MAB" <mbeck...@gmail.comwrote:
>
Quote:
Quote:
I have the following function:
>
Quote:
Quote:
function doStuff(str) {
var DataSite="test1a.asp?q="+str;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = DataSite;
document.getElementsByTagName('head')[0].appendChild(script);
var x = doMoreStuff();
}
>
Quote:
Quote:
The function loads an asp page into memory. I am looking for a cross
browser solution to test to see if the page is fully loaded before
doMoreStuff is called. Can anyone offer some code or point me in the
right direction? Thanks.
>
Quote:
I'm guessing that either doMoreStuff or something that doeMoreStuff
needs is in the script you are trying to load. You may want to try
using a try catch statement. That way if you get an exception b/c you
are trying to access an element that has not been created (or a
similar exception) in the catch you can set the timeout for 2 seconds
(or whatever you think is best).
>
Thanks for the response. the doMoreStuff function process the data
from the page that was loaded. Unfortunately, it tries to do it
before the page finishes loading. As a result, I get no data the
first time it is run and I remain one iteration behind the data
generation.
>
I would prefer not to use a timeout as I will simpley have to guess
how long it will take to run.
>
Other ideas?- Hide quoted text -
>
- Show quoted text -
You're not going to get any kind of notification event, if that's what
you're looking for. You could try something like:

function doMoreStuffWhenReady() {
try {
doMoreStuff();
}
catch(e) {
doMoreStuffWhenReady();
}
}

Then from your function call doMoreStuffWhenReady() instead of
doMoreStuff. The idea is that it will continue to try to doMoreStuff
until there are no exceptions.

I have NO idea what kind of processor usage implications this would
have. But test it.

Closed Thread