-1
I wonder how I can make the script below work as follows in case it and a countdown comes the put it in case it makes a count taking a date posted on it and comparing with the current date doing the count in the case there when it comes to 0
message appears.
The case is that I would like to know how to put this script to work as follows, he doing a 30 second count every time the page is updated then pass the 30 seconds appear the text and I need him to do this calculation as I said taking the current date and if update the page as said the count returns again.
Below the scripts
index.html
<!doctype html>
<html>
<head>
<title>Contador em PHP</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// Requisicao AJAX
var requisicao = function(){
$.ajax({
url: "contador.php"
}).done(function(resultado){
// Exibe o resultado no elemento com ID contador
$("#contador").html(resultado);
});
};
// Executa a requisicao com intervalo de 100ms
setInterval(requisicao, 100);
});
</script>
</head>
<body>
<p>Faltam <span id="contador"></span> segundos para o fim do mundo!</p>
</body>
</html>
php counter.
<?php
// Define as datas
$data_atual = date('d-m-Y h:i:s');
$data_final = date('2015-12-21');
// Converte as datas para a hora UNIX e realiza o calculo da diferenca
$diferenca = strtotime($data_final) - strtotime($data_atual);
// Exibe o resultado se ele for positivo. Caso seja negativo, exibe 0.
echo ($diferenca >= 0) ? $diferenca : 0;
?>
jQuery.js too big to be put here.
The reason for the change and adapt it to show Urls.
Try to explain better why to use Javascript and not PHP and why to do it this way.
– Jorge B.
Or put another way, code is cool but an explanation, however small, makes the answer much more useful to visitors].
– brasofilo