Other Software > Developer's Corner
[JS] How to make this loop?
(1/1)
RedPillow:
--- Code: Javascript ---$(document).ready(function(){ var modTime = 0;setInterval(function(){ $.post("ChatClient.php", {"file":"chat.cht", "time":modTime}, function(rst) { if (rst.time != modTime) { modTime = rst.time; window.location.reload(); else { } } });}, 1000);});
So that is my code, and I need to make it do the whole check again on the else-statemen.
This is supposed to check a file modification time and if it's changed - it should reload the page and if it's not changed, it should just keep checking infinitely again until it is.
It works nice, if I remove the else-statement but then it refreshes every seconds - no matter if the file is modified or not.
I tried this by myself:
--- Code: Javascript ---$(document).ready(function(){loopIt();function loopIt() { var modTime = 0;setInterval(function(){ $.post("ChatClient.php", {"file":"chat.cht", "time":modTime}, function(rst) { if (rst.time != modTime) { modTime = rst.time; window.location.reload(); else { loopIt(); } } });}, 1000);}});
Navigation
[0] Message Index
Go to full version