Viktor Svensson
Viktor Svensson

Reputation: 755

Ajax sometimes freezes

This code is supposed to request new chat messages and append them to the content on my website. The problem, though, is that it sometimes freezes and stops requesting new messages.

(function worker() {
    $.ajax({
        url: '/client_message.php?get_message=yes&chat_id=<?php echo $chat_id; ?>&user_id=<?php echo $uid; ?>', 
        success: function(data) {
            content = data;
            if(content != "" && content != prev) {
                $("#chat_wrapper").append(content);
                prev = content;
                $("html, body").animate({ scrollTop: $(document).height() }, "slow");
                titleStuff();
            }
        },
        complete: function() {
            setTimeout(worker, 700);
        }
    });
})();

Please let me know if you need more information to figure out what could be wrong.

Upvotes: 0

Views: 260

Answers (1)

Viktor Svensson
Viktor Svensson

Reputation: 755

Adding this code did the trick:

$.ajaxSetup({ cache: false });

Seems like the problem was a result of the jQuery cache.

Upvotes: 1

Related Questions