Jump to content

Recommended Posts

It is a countdown that eventually would get the new date to count down to from a MySQL query. But it can change often and needs to refresh every second.

 

Live example: http://www.mp3joe.com

 

Not sure why it keeps disapearing like it is.

 

index.php:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<head>
    <script type="text/javascript">// <![CDATA[
    $(document).ready(function() {
    $.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
    setInterval(function() {
    $('#results').load('data.php');
    }, 5000); // the "3000" here refers to the time to refresh the div. it is in milliseconds.
    });
    // ]]></script>



</head>

<div id="results">Loading users...</div>

data.php:

<head>
<link rel="stylesheet" href="jquery.countdown.css">
<style type="text/css">
#defaultCountdown { width: 240px; height: 45px; }
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.countdown.js"></script>
<script type="text/javascript">
$(function () {
	var austDay = new Date();
	austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
	$('#defaultCountdown').countdown({until: austDay});
	$('#year').text(austDay.getFullYear());
});
</script>
</head>


<div id="defaultCountdown"></div>

Link to comment
https://forums.phpfreaks.com/topic/283287-refreshing-countdown-makes-it-disappear/
Share on other sites

The link you provided brings up a "server not found" error.

 

But, looking at the code, a few things jump out at me. The index page seems incomplete - e.g. html tags are missing, no opening body tag, a javascript is outside the head tags, etc.

 

So, assuming the index page is complete, the javascript is loading data into a div from the data.php page. But, the data.php page has HTML elements that already exist int he main page (e.g. HTML and HEAD tags. Several javascript includes as well as a function. That doesn't make sense to me. I'm sure your problem is with that. The JavaScript in the index page should not be getting new dynamic javascript to be run.

Sorry, here is the link http://82.145.36.70/

 

So other than that the script is fine?

 

Is there not a way to have a refreshing function that gets a single value for the date from another page?

 

Rather than reload the clock script each time?

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.