Show new records added like as chat

Discussion in 'JavaScript' started by piropeator, Mar 15, 2011.

  1. #1
    This is my list:
    [​IMG]
    The index.html code:
    <script language="javascript" src="ajax.js"></script>
    
    <script language="javascript">
         http = getXMLHTTPRequest();
    
         function generalista(){
              var myurl = 'cliente_lista.php';
              myRand= parseInt(Math.random()*99999999999999999);
              var modurl = myurl + "?rand=" + myRand;
              http.open("GET", modurl, true);
              http.onreadystatechange = useHTTPResponse;
              http.send(null);
         }
    
         function useHTTPResponse() {
              if (http.readyState == 4) {
                   if(http.status == 200) {
                        var miTexto = http.responseText;
                            document.getElementById('listacliente').innerHTML = (miTexto);
                            http.onreadystatechange = null;
                        }
                        } else {
                        document.getElementById('listacliente').innerHTML='<img src="procesando.gif">';
                   }
         }
    
    </script>
    <body onLoad="generalista()">
    <table width="500" border="0" cellspacing="0" cellpadding="0">
         <tr>
              <td> <div id="listacliente"></div></td>
         </tr>
    </table>
    </body>
    PHP:
    I want to display automatically all list when a new record was entered in data base, as when a chat window shows a new line.:confused:
     
    piropeator, Mar 15, 2011 IP
  2. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Put a timer which e.g. every 5 seconds sends a AJAX request to PHP and get actual data...

    instead of <body onLoad="generalista()">

    use

    window.setInterval('generalista()', 5000)
    inside your <script> tag
     
    Jan Novak, Mar 17, 2011 IP