Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/08/2012, 05:58
Avatar de Silkon
Silkon
 
Fecha de Ingreso: mayo-2011
Ubicación: Lugo
Mensajes: 201
Antigüedad: 13 años
Puntos: 20
Actualizar ventana solo cuando hay cambios??

Hola a todos.

A ver si me podeis ayudar, por que me voy dar por vencido de hacerlo con ajax xD

Quiero actualizar una lista de nicks mediante ajax, pero solo cuando hay algun cambio. Ahora lo tengo por tiempo asi.

window.setInterval("actualizar()", 3000);


function llamadaAjax()
{
var xmlhttp;
if (window.XMLHttpRequest)
{

xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{

xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
alert("Tu navegador no soporta XMLHTTP!");
}
xmlhttp.onreadystatechange=function()
{

if(xmlhttp.readyState==4)
{
document.getElementById('chatnicksact').innerHTML= xmlhttp.responseText;
document.getElementById('chatnicksact').style.back groundColor = '#550000';
}
}
xmlhttp.open("GET","listanicks.php",true);
xmlhttp.send(null);
}

function actualizar() {
llamadaAjax();
}


Intente cambiar la primera linea de actualizar por tiempo, por algo asi

onreadystatechange = actualizar;
onreadystatechange = actualizar();


Pero no funciona... Como podria hacer que solo actualice al existir cambios en la lista?