Jump to content

Refresher


leequalls

Recommended Posts

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

  • 2 weeks later...

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.