Ver Mensaje Individual
  #5 (permalink)  
Antiguo 05/12/2011, 19:11
pablobuitres
 
Fecha de Ingreso: octubre-2010
Ubicación: montevideo
Mensajes: 169
Antigüedad: 13 años, 7 meses
Puntos: 5
Respuesta: llamar consulta mysql con ajax que actualice sin tocar F5

Hola amigo, no he podido instrumentar tu solución, tengo el siguiente código que me da el problema que al recargarse pestanea, se los muestro y agradesco ayuda para evitar que esto pase muchas gracias por todo!

Código Javascript:
Ver original
  1. <html>
  2.  
  3. <script language="javascript"  type="text/javascript">
  4. var RequestObject = false;
  5.   var Archivo = 'noticias_nuevared.php?id=<?php echo $_GET['id'];?>&alguien=<?php echo $_GET['alguien'];?>'; //directorio donde tenemos el archivo ajax.php
  6.   window.setInterval("actualizacion_reloj()", 60000); // el tiempo X que tardará en actualizarse
  7.   if (window.XMLHttpRequest) //
  8. RequestObject = new XMLHttpRequest();
  9. if (window.ActiveXObject)
  10.   RequestObject = new ActiveXObject("Microsoft.XMLHTTP");
  11. function ReqChange() {
  12. // Si se ha recibido la información correctamente
  13.   if (RequestObject.readyState==4) {
  14.   // si la información es válida
  15.   if (RequestObject.responseText.indexOf('invalid') == -1)
  16.   {
  17.   // Buscamos la div con id online
  18.   document.getElementById("online").innerHTML = RequestObject.responseText;
  19.   }
  20.   else {
  21.   // Por si hay algun error
  22.   document.getElementById("online").innerHTML = "Error llamando";
  23.   }
  24.   }
  25.   }
  26. function llamadaAjax() {
  27.  // Mensaje a mostrar mientras se obtiene la información remota...
  28.   document.getElementById("online").innerHTML = "";
  29.   // Preparamos la obtención de datos
  30.   RequestObject.open("GET", Archivo+"?"+Math.random() , true);
  31.   RequestObject.onreadystatechange = ReqChange;
  32.   // Enviamos
  33.   RequestObject.send(null);
  34.   }
  35.   function actualizacion_reloj() {
  36.   llamadaAjax();
  37.   }
  38. </script>
  39. <body onload="llamadaAjax();">
  40.  
  41.   <div id="online"><script type="text/javascript">
  42. <![CDATA[
  43. setInterval("mostrar_consulta('codigo.php')", 5000);
  44. // tiempo en milisegundos
  45. //]]>
  46. </script></div>
  47.  
  48.  
  49.  
  50.  
  51. </body>
  52. </html>