Ver Mensaje Individual
  #7 (permalink)  
Antiguo 28/04/2009, 05:32
magicrat
 
Fecha de Ingreso: abril-2009
Mensajes: 13
Antigüedad: 15 años
Puntos: 0
Respuesta: Refresco JS - PHP

Vuelvo a poner el codigo entreo a continuación, pero de manera ordenada (lo siento, pero me daba errores de permisos para linkks/url y por eso los mensajes anteriores en lugar de ponerlo todo seguido y correcto).

Bàsicamente: html llama a un JS q llama un método q ser fresca cada minuto.
Este JS llama a otoro js q a su vez llama al PHP que da la hora del servidor.

El problema es que l ahora del servidor no se refresca.

Saludos y muchas gracias.

<!--
//--------------------------------------------------------------------------
// testHora.html
//--------------------------------------------------------------------------
-->
<html>
<head>
<meta http-equiv="content-type" content="text/html;" charset="ISO-8859-1"/>
<title>TEST HORA SERVIDOR</title>
<script src="./js/testMain.js" type="text/javascript" charset="iso-8859-1"></script>
<script src="./js/testUtils.js" type="text/javascript" charset="iso-8859-1"></script>
<script src="./js/testUtils.php" type="text/javascript" charset="iso-8859-1"></script>
</head>
<body bgcolor="#F7F8F9" onload="TEST_MAIN.main()">
<H1>Hora del Servidor</H1><BR>
<div id="horaServidor"></div>
</body>
</html>


//--------------------------------------------------------------------------
// testMain.js
//--------------------------------------------------------------------------

//<![CDATA[

TEST_MAIN = {};

TEST_MAIN.main = function () {
TEST_MAIN.update();
}

TEST_MAIN.update = function () {
alert( "TEST_MAIN.update" ); // Alert para comprobar que el método se llama OK.
var d = TEST_UTILS.getServerDate();
document.getElementById('horaServidor').innerHTML = d;
setTimeout("TEST_MAIN.update()", 1*60*1000); // Timer 1min
}

//]]>


//--------------------------------------------------------------------------
// testUtils.js
//--------------------------------------------------------------------------

//<![CDATA[

TEST_UTILS = {};

TEST_UTILS.getServerDate = function () {
return TEST_UTILS_PHP.getServerTime();
}

//]]>


//--------------------------------------------------------------------------
// testUtils.php
//--------------------------------------------------------------------------

//<![CDATA[

TEST_UTILS_PHP = {};

TEST_UTILS_PHP.getServerTime = function () {
// Aunque ponga el header de no-cache, no se refresca la fecha
var currentTime = '<?php print date("F d, Y H:i:s", time())?>';
//var currentTime = '<?php header( "Cache-control: no-cache" ); header( "Expire: -1" ); print date("F d, Y H:i:s", time())?>';
var serverTime = new Date(currentTime);
return serverTime;
}

//]]>