All pastes #33968 Raw Edit

Miscellany

public text v1 · immutable
#33968 ·published 2005-12-17 16:32 UTC
rendered paste body
var req1; 

function listar(url) 
{ 
    req1 = null; 
    // Procura por um objeto nativo (Mozilla/Safari) 
    if (window.XMLHttpRequest) { 
        req1 = new XMLHttpRequest(); 
        req1.onreadystatechange = process_lista; 
        req1.open("GET", url, true); 
        req1.send(null); 
    // Procura por uma versão ActiveX (IE) 
    } else if (window.ActiveXObject) { 
        req1 = new ActiveXObject("Microsoft.XMLHTTP"); 
        if (req1) { 
            req1.onreadystatechange = process_lista; 
            req1.open("GET", url, true); 
            req1.send(); 
        } 
    } 
} 

function process_lista() 
{ 
    // apenas quando o estado for "completado" 
    if (req1.readyState == 4) { 
        // apenas se o servidor retornar "OK" 
        if (req1.status == 200) { 
            // procura pela div id="news" e insere o conteudo 
            // retornado nela, como texto HTML 
            document.getElementById('lista').innerHTML = req1.responseText; 
        } else { 
            alert("Houve um problema ao obter os dados:\n" + req1.statusText); 
        } 
    } 
} 

function online(obj) 
{ 
    listar("lista.php"); 
} 

// Recarrega a cada 60000 milissegundo (60 segundos) 
setInterval("online()", 5000);