function chatUpdate() {
    var xmlhttp = new XMLHttpRequest();
    var url = document.URL + '&action=update';
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var myArr = JSON.parse(xmlhttp.responseText);
                alert(myArr);
        }
    }
    xmlhttp.open("GET", url, true);
    xmlhttp.send();
}
setInterval(chatUpdate(), 1000);
This code updates chat every 3 seconds. It alerts myArr correctly (I just alert it for debug purposes), but just for one time – when page loads (but I need it every 3 seconds), although a setInterval is called.
I think the problem is (it must be) that onreadystatechange / readyState are not updated after first request. I tried really hard but I did not succeed in it.
Please, help
 
    