long poll via .getJSON wierdness on IE7

long poll via .getJSON wierdness on IE7

I'm using long polling for a simple chat.  On IE7, however, something bizarre happens:

function longPoll () {
    var data = new Object();
    data['room'] = document.getElementById('room').innerHTML;
    data['user'] = document.getElementById('username').value;
alert("poll!") // debug
    $.getJSON('/chat', escape(JSON.stringify(data)), function (resp, status) {
        if (!resp) {
            setTimeout('longPoll()', 250);    /* Chrome needs delay */
            return;
        }
        for (var i = 0; i < resp['update'].length; i++) {
            var update = document.createElement('p');
            update.className = 'chatmessg';
            update.innerHTML = resp['update'];
            Mbox.appendChild(update);
            Mbox.scrollTop = Mbox.scrollHeight;
        }
        setTimeout('longPoll()', 250);    /* Chrome needs delay */
    });
}   

The server returns the first poll immediately; after that, it does not reply until there is something to add (ie, irregularly).  But on IE7, the $.getJSON "success" function fires repeatedly and endlessly from the start;  the data from the first call is used over and over -- the alert happens, then the appendChild with the exact same message gets added to the display.  Only the first call actually gets sent, the rest are not.

The only way to stop this is to kill IE.  Works as expected in FF, Chrome, Safari.



























    • Topic Participants

    • mk