leequalls Posted March 14, 2011 Share Posted March 14, 2011 I would like the following code to stop refreshing after 5 seconds here is the code I am using main page inside <head></head> <script type="text/javascript"> $(document).ready( function(){ var refreshCountdown = setInterval( function() { $.get( "ajaxTimer.php", {}, function( data ){ $("#countdownBlock").html( data ); }); }, 1000 ); }); </script> ajaxTimer.php $countdownSeconds = $_SESSION['timer']; echo "Programming begins in ".$countdownSeconds; if($_SESSION['timer'] == 0) { $_SESSION['countdownActive'] = "False"; } $_SESSION['timer'] = $countdownSeconds-1; Link to comment https://forums.phpfreaks.com/topic/230561-refresher/ Share on other sites More sharing options...
monkeytooth Posted March 27, 2011 Share Posted March 27, 2011 Original <script type="text/javascript"> $(document).ready( function(){ var refreshCountdown = setInterval( function() { $.get( "ajaxTimer.php", {}, function( data ){ $("#countdownBlock").html( data ); }); }, 1000 ); }); </script> New <script type="text/javascript"> var countfrom = 0; var counttil = 5; $(document).ready( function(){ var refreshCountdown = setInterval( function() { if(countfrom == counttil){clearInterval(refreshCountdown);}else{ $.get( "ajaxTimer.php", {}, function( data ){ $("#countdownBlock").html( data ); countfrom = countfrom+1 } }); }, 1000 ); }); </script> Link to comment https://forums.phpfreaks.com/topic/230561-refresher/#findComment-1192777 Share on other sites More sharing options...
monkeytooth Posted March 27, 2011 Share Posted March 27, 2011 All i did was add an if statement to your existing interval, that checks to see if there is a specific count of x.. where if that count is met it clears the interval timer that you set so it will stop running at that point Link to comment https://forums.phpfreaks.com/topic/230561-refresher/#findComment-1192778 Share on other sites More sharing options...
leequalls Posted March 27, 2011 Author Share Posted March 27, 2011 I tried you new code however the div does not load all it does is say Loading... and nothing happens. Link to comment https://forums.phpfreaks.com/topic/230561-refresher/#findComment-1192781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.