Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.