Connecting Tech Pros Worldwide Help | Site Map

ReadyState issues

  #1  
Old March 1st, 2007, 11:15 PM
MAB
Guest
 
Posts: n/a
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.

  #2  
Old March 2nd, 2007, 03:05 PM
Mister Joe
Guest
 
Posts: n/a

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).

  #3  
Old March 2nd, 2007, 06:15 PM
MAB
Guest
 
Posts: n/a

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?

  #4  
Old March 2nd, 2007, 09:35 PM
Tom Cole
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
AJAX - resObjekt.readyState is only 1 Mark Knochen answers 2 November 20th, 2006 12:15 PM
After making a AJAX request from .js file the readystate propertyof the Http object is not changing (remains constantly @ 1) Mathan Babu answers 0 September 19th, 2006 09:55 AM
Javascript concurrency issues... Ben Kolera answers 2 July 13th, 2006 01:15 AM