Skip to content Skip to sidebar Skip to footer

JQuery, Compare Content Before Loading

How would I go around updating a divs content, if the old content and the new content aren't the same. Only update if it's the same. As in, let's say. Currently I have this:

Solution 1:

Use $.get() instead of .load().

var $main = $('.main');
$.get('ajax/display_messages.php', function (data)
{
    if ($main.html() !== data) $main.html(data);
});

Solution 2:

$(setInterval(function()
{
    $.get('ajax/display_messages.php',function(response)
        { 
            if( $('.main').html() != response ) 
            { 
                $('.main').html(response);
            }
        });
}, 2000));

Post a Comment for "JQuery, Compare Content Before Loading"