469,332 Members | 6,987 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

how to wait x amout of seconds during an ajax call

ok i want to wait an x amout of seconds before my ajax script writes
the results to a div, but i want it to still display the loading bar, i
do have a variable http_rste that holds the readyState and the if
statements check that instead just incase i have a need to have the
thing stay there an x amount of seconds but i could never get the
script right

Jun 4 '06 #1
9 5317

Jordan Pittman wrote:
ok i want to wait an x amout of seconds before my ajax script writes
the results to a div, but i want it to still display the loading bar, i
do have a variable http_rste that holds the readyState and the if
statements check that instead just incase i have a need to have the
thing stay there an x amount of seconds but i could never get the
script right


Please post your current ajax response handler function..

Peter

Jun 4 '06 #2
Jordan Pittman wrote:
ok i want to wait an x amout of seconds before my ajax script writes
the results to a div, but i want it to still display the loading bar, i
do have a variable http_rste that holds the readyState and the if
statements check that instead just incase i have a need to have the
thing stay there an x amount of seconds but i could never get the
script right


There is no way of suspending execution in javascript. If you want something to happen in x seconds, the usual thing is to do

setTimeout(funcRef, milliseconds);
Jun 4 '06 #3
i have tried creating a function to just handle the readyState 4 but it
did not work correctly
and i tried SetTimeout and it did not do any good either
TheBagbournes wrote:
Jordan Pittman wrote:
ok i want to wait an x amout of seconds before my ajax script writes
the results to a div, but i want it to still display the loading bar, i
do have a variable http_rste that holds the readyState and the if
statements check that instead just incase i have a need to have the
thing stay there an x amount of seconds but i could never get the
script right


There is no way of suspending execution in javascript. If you want something to happen in x seconds, the usual thing is to do

setTimeout(funcRef, milliseconds);


Jun 4 '06 #4
Jordan Pittman said the following on 6/4/2006 7:52 AM:
i have tried creating a function to just handle the readyState 4 but it
did not work correctly
and i tried SetTimeout and it did not do any good either


My stereo doesn't work. I have some wires hooked up. Why doesn't it play?

Oh, you need to see what doesn't work to tell what is wrong with it?

If the two options you say you tried didn't work, then you didn't code
them correctly and the only way to tell what is wrong with that code is
to see the code.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 4 '06 #5
Jordan Pittman wrote:
i have tried creating a function to just handle the readyState 4 but it
did not work correctly
and i tried SetTimeout and it did not do any good either


It sounds like the functions are not executing in the scope you are expecting - they do not have the correct "this".

You might need to bind them using a closure:

var me = this; // or whatever is going to be the context on execution
setTimeout(function()
{
theRealFunction.call(me);
}, 1000);

That will execute theRealFunction in the scope of whatever object "me" references one second later.
Jun 4 '06 #6
i dont use "this" in javascript unless required also i just want a way
to set a variable to something after x amount of seconds if a certian
requirement is met then if that variable equals to something then
execute this else done execute it

TheBagbournes wrote:
Jordan Pittman wrote:
i have tried creating a function to just handle the readyState 4 but it
did not work correctly
and i tried SetTimeout and it did not do any good either


It sounds like the functions are not executing in the scope you are expecting - they do not have the correct "this".

You might need to bind them using a closure:

var me = this; // or whatever is going to be the context on execution
setTimeout(function()
{
theRealFunction.call(me);
}, 1000);

That will execute theRealFunction in the scope of whatever object "me" references one second later.


Jun 5 '06 #7
Jordan Pittman wrote:
i dont use "this" in javascript unless required
Why not?
http://www.quirksmode.org/js/this.html
Ah -
"Unfortunately it is hard to use if you don't exactly know how it works."
also i just want a way
to set a variable to something after x amount of seconds if a certian
requirement is met then if that variable equals to something then
execute this else done execute it


Again, easy enough to do with setTimeOut. Just have the function that
you set on timeout test the variable.
Jun 5 '06 #8
easier said then done,
i have tried using an external function and it failed completely infact
it never returned the results after 5 seconds
Tony wrote:
Jordan Pittman wrote:
i dont use "this" in javascript unless required


Why not?
http://www.quirksmode.org/js/this.html
Ah -
"Unfortunately it is hard to use if you don't exactly know how it works."
also i just want a way
to set a variable to something after x amount of seconds if a certian
requirement is met then if that variable equals to something then
execute this else done execute it


Again, easy enough to do with setTimeOut. Just have the function that
you set on timeout test the variable.


Jun 6 '06 #9
Jordan Pittman wrote:
easier said then done,
i have tried using an external function and it failed completely infact
it never returned the results after 5 seconds
a) please don't top-post

b) Hard to tell what's wrong without the code. I'd say, offhand, that
you're making the setTimeOut call incorrectly. Either that, or you're
not handling the variable right.

Tony wrote:
Jordan Pittman wrote:
i dont use "this" in javascript unless required


Why not?
http://www.quirksmode.org/js/this.html
Ah -
"Unfortunately it is hard to use if you don't exactly know how it works."

also i just want a way
to set a variable to something after x amount of seconds if a certian
requirement is met then if that variable equals to something then
execute this else done execute it


Again, easy enough to do with setTimeOut. Just have the function that
you set on timeout test the variable.


Jun 6 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Erwin Kloibhofer | last post: by
15 posts views Thread by Snuyt | last post: by
4 posts views Thread by PJ6 | last post: by
4 posts views Thread by louvino | last post: by
5 posts views Thread by MattC | last post: by
40 posts views Thread by =?Utf-8?B?Um9iZXJ0IEUuIEZsYWhlcnR5?= | last post: by
5 posts views Thread by Jeremy | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.