Ver Mensaje Individual
  #3 (permalink)  
Antiguo 10/06/2012, 16:35
Requenaeo
 
Fecha de Ingreso: marzo-2011
Ubicación: Punta de Mata
Mensajes: 106
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: Sistema de tiempo real.

ok no hay problema yo tengo entendido que es por ajax pero toda los codigo que he hecho simpre hace lo ya dicho borra lo seleccionado de todo modaos te voy a dejar 2 codigo para que lo veas
Código Javascript:
Ver original
  1. var seconds = 3; // el tiempo en que se refresca
  2.     var divid = "comment-conte"; // el div que quieres actualizar!
  3.     var url = "comentarios.php"; // el archivo que ira en el div
  4.  
  5.     function refreshdiv(){
  6.  
  7.         // The XMLHttpRequest object
  8.  
  9.         var xmlHttp;
  10.         try{
  11.             xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
  12.         }
  13.         catch (e){
  14.             try{
  15.                 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
  16.             }
  17.             catch (e){
  18.                 try{
  19.                     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  20.                 }
  21.                 catch (e){
  22.                     alert("Tu explorador no soporta AJAX.");
  23.                     return false;
  24.                 }
  25.             }
  26.         }
  27.  
  28.         // Timestamp for preventing IE caching the GET request
  29.         var timestamp = parseInt(new Date().getTime().toString().substring(0, 10));
  30.         var nocacheurl = url+"?t="+timestamp;
  31.  
  32.         // The code...
  33.  
  34.         xmlHttp.onreadystatechange=function(){
  35.             if(xmlHttp.readyState== 4 && xmlHttp.readyState != null){
  36.                 document.getElementById(divid).innerHTML=xmlHttp.responseText;
  37.                 setTimeout('refreshdiv()',seconds*1000);
  38.             }
  39.         }
  40.         xmlHttp.open("GET",nocacheurl,true);
  41.         xmlHttp.send(null);
  42.     }
  43.  
  44.     // Empieza la función de refrescar
  45.  
  46.     window.onload = function(){
  47.         refreshdiv(); // corremos inmediatamente la funcion
  48.     }
este es el que yo naturalmente utilizo

Código Javascript:
Ver original
  1. var UltFec;
  2. function consultaMensajes(){
  3.   divResultado = document.getElementById('pagina');
  4.   ajax=objetoAjax();
  5.   ajax.open("GET", "consulta.php?ultfec="+UltFec,true);
  6.   ajax.onreadystatechange=function() {
  7.    if (ajax.readyState==4) {
  8.     //obtenemos los resultados XML;
  9.     var datos=ajax.responseXML.documentElement;
  10.     //mediante manejo de DOM accedemos a los elementos del XML
  11.     for (i = 0; i < datos.getElementsByTagName('elemento').length; i++){
  12.      var item = datos.getElementsByTagName('elemento')[i];
  13.      var fec = item.getElementsByTagName('fecha')[0].firstChild.data;
  14.      var usu = item.getElementsByTagName('usuario')[0].firstChild.data;
  15.      var men = item.getElementsByTagName('mensaje')[0].firstChild.data;
  16.      var linea='<div class="c_fecha">'+fec+'</div><div class="c_usuario">'+usu+'</div><div class="c_mensaje">'+men+'</div>';
  17.      CrearCaja(linea);
  18.     }
  19.     //si ultima fecha esta definida se usará
  20.     //caso contrario se dejara con su valor anterior
  21.     if(typeof fec!='undefined'){
  22.      UltFec=fec;
  23.     }
  24.    }
  25.   }
  26.   ajax.send(null)
  27.   //consultar mensaje nuevos cada 3 seg.
  28.   setTimeout('consultaMensajes();',3000);
  29.  }
  30.  
  31. //cuando se carga la pagina principal consultamos los mensajes
  32.  window.onload = function (){
  33.   consultaMensajes();
  34.  }
este otro lo descubri pero e tenenidos varios inconveniente como que al pasa los comentarios que los pide en XML siempre se repiten una y otro vez.