Does JavaScript time out?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Does JavaScript time out?

Post by WaldoMonster »

I have made a PHP script that updates the playlis every second with innerHTML.
The server will send every second something like this:

Code: Select all

<script type="text/javascript">document.getElementById('time').innerHTML='00:03';</script>
This is working well, but I have to refresch the page after some time to prevent browser timeout.

Isn't it possible to make a page with an endless JavaScript loop witch will get the desired data every second with an AJAX request?
Or will the JavaScript eventually time out?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It is possible to do with Ajax, yes.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Interval window.setInterval(Function function, Integer timeout)

Code: Select all

window.setInterval(function() { yourAjaxMethod(); }, 2000);
Calls "yourAjaxMethod()" every 2 seconds.
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

I could use setInterval for updating the playtime.
This way you can update the playtime every second.
With a slow server or client the previous update could not be ready before setInterval starts the next function.
Than setTimeout would be a better solution.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

some ajax calls will take more than a second to load, be careful there.
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

I think I will use setTimeout after evaluating the AJAX request.
This would be safe with a slow server or client.
Post Reply