Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 10, 2016, 08:19:25 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: [JS] How to make this loop?  (Read 1082 times)

RedPillow

  • Member
  • Joined in 2008
  • **
  • Posts: 141
  • Pillows.
    • View Profile
    • Read more about this member.
    • Donate to Member
[JS] How to make this loop?
« on: March 30, 2011, 08:29:18 AM »
Code: Javascript [Select]
  1. $(document).ready(function(){
  2.  
  3.    var modTime = 0;
  4. setInterval(function(){
  5.   $.post("ChatClient.php", {"file":"chat.cht", "time":modTime}, function(rst) {
  6.     if (rst.time != modTime) {
  7.       modTime = rst.time;
  8.                 window.location.reload();
  9.         else {
  10.                        
  11.         }
  12.     }
  13.   });
  14. }, 1000);
  15. });

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 [Select]
  1. $(document).ready(function(){
  2. loopIt();
  3. function loopIt() {
  4.    var modTime = 0;
  5. setInterval(function(){
  6.   $.post("ChatClient.php", {"file":"chat.cht", "time":modTime}, function(rst) {
  7.     if (rst.time != modTime) {
  8.       modTime = rst.time;
  9.                 window.location.reload();
  10.         else {
  11.                 loopIt();      
  12.         }
  13.     }
  14.   });
  15. }, 1000);
  16. }
  17. });
« Last Edit: March 30, 2011, 08:41:58 AM by RedPillow »