Ver Mensaje Individual
  #5 (permalink)  
Antiguo 28/07/2013, 10:18
BLADDE
 
Fecha de Ingreso: abril-2006
Mensajes: 72
Antigüedad: 18 años, 1 mes
Puntos: 0
Respuesta: Detectar e Informar sobre Cambios registrados en tiempo real

bue creo que lo resolvi quedando asi:
index.php
Código PHP:
 <?php
 session_start
();
  function 
hay_nuevos_ticket($username)
 {
     include 
'conexion.php';
     
$sql="select id_incidencias,id_ruta from ticket where recibe='$username' and (status='Asignada')";
                       
$consulta=mysql_query($sql) or die (mysql_error());  
                              if(
$res=mysql_fetch_object($consulta)){
                              return 
"Tiene Nuevos Tickets Asignados";
                             }else{
                             return 
"NO Tiene Nuevos Tickets Asignados";
                              }
     
     }
if(
$_POST)  
$username=$_SESSION['s_user_username'];
    
set_time_limit(0);    
    
header("Edge-control: no-store");
    
usleep(1000);
    
$content hay_nuevos_ticket($username);
    while(
$content=='')
    {
        
usleep(1000);
        
$content hay_nuevos_ticket($username);
    }
    echo 
$content;
    exit();
}
?>  
<html>
<head>    
</head>
<body>

    <div id="content">cargando</div>
<script type="text/javascript" src="comet.js"></script>
</body>
</html>
comet.js
Código:
var xmlhttp = function()
    {
        var a;try{a = new XMLHttpRequest();}
        catch(e){try{a = new ActiveXObject('Msxml2.XMLHTTP');}
        catch(e){try{a = new ActiveXObject('Microsoft.XMLHTTP');}
        catch(e){alert('Your browser doesn\'t support ajax');a=false;}
        }}return a;
    };  
    window.onload = function()
    {
        var a = new comet();
    };  
    var comet = function()
    {
        var a = new xmlhttp();
        a.open('post',window.location+"?"+Math.random()+"="+Math.random(), true);
        a.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        a.onreadystatechange = function()
        {
            if(a.readyState == 4)
            {
                document.getElementById('content').innerHTML = a.responseText;
                window.setTimeout(function(){
                    a = new comet();                    
                },1000);
                
            }
        };
        a.send('algo=algo');                
    };
recomendaciones para optimizar? mejores formas de hacerlo? acepto cualquier sugerencia saludos