Ver Mensaje Individual
  #11 (permalink)  
Antiguo 02/02/2011, 23:25
Avatar de goteen_mx
goteen_mx
 
Fecha de Ingreso: abril-2005
Ubicación: D.F.
Mensajes: 403
Antigüedad: 19 años
Puntos: 37
Respuesta: como obtener la fecha actual sin refrescar la pagina?

es JavaScript no Java

y bueno necesitas 2 archivos

ver_fecha.html y get_fecha.php

en el primero

Código HTML:
Ver original
  1. <script type="text/javascript">
  2. function f_getFecha()
  3. {
  4. if (window.XMLHttpRequest)
  5.   {// code for IE7+, Firefox, Chrome, Opera, Safari
  6.   xmlhttp=new XMLHttpRequest();
  7.   }
  8. else
  9.   {// code for IE6, IE5
  10.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  11.   }
  12. xmlhttp.onreadystatechange=function()
  13.   {
  14.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  15.    {
  16.    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
  17.     }
  18.   }
  19. xmlhttp.open("GET","get_fecha.php",true);
  20. xmlhttp.send();
  21. }
  22. </head>
  23.  
  24.  
  25. <div id="myDiv"></div>
  26. <button type="button" onclick="f_getFecha()">Imprime Fecha</button>
  27.  
  28. </body>
  29. </html>

en el segundo

Código PHP:
Ver original
  1. <?php
  2.    echo "Fecha del dia de hoy: ". date();
  3. ?>
  4.  
  5. Este código te llena la fecha obtenida por el archivo php en el div que le indicas

fuente: w3schools

Saludos.