Page 1 of 1

Does JavaScript time out?

Posted: Thu May 03, 2007 4:51 am
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?

Posted: Thu May 03, 2007 7:06 am
by feyd
It is possible to do with Ajax, yes.

Posted: Thu May 03, 2007 8:14 am
by Chris Corbyn
Interval window.setInterval(Function function, Integer timeout)

Code: Select all

window.setInterval(function() { yourAjaxMethod(); }, 2000);
Calls "yourAjaxMethod()" every 2 seconds.

Posted: Thu May 03, 2007 2:47 pm
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.

Posted: Thu May 03, 2007 5:33 pm
by Kieran Huggins
some ajax calls will take more than a second to load, be careful there.

Posted: Fri May 04, 2007 4:45 am
by WaldoMonster
I think I will use setTimeout after evaluating the AJAX request.
This would be safe with a slow server or client.