I'm having issues comparing current list items on a page with ones that are retrieved through a PHP AJAX refresh. I only want the box to refresh if there are new items.
The PHP returns a bunch of formatted, HTML list items.
<ul class="socialFeed twitterFeed">
<script type="text/javascript">
$(function() {
refreshTweets();
});
function refreshTweets() {
$.get("php/tweets.php", function(data){
var current = $(".socialFeed.twitterFeed").html();
if(current != data) {
$(".socialFeed.twitterFeed").hide().html(data).fadeIn();
}
});
}
setInterval("refreshTweets()", 2000);
</script>
</ul>
I can't figure out why the string comparison isn't working. I'm missing something, but I'm not sure what.
Try this:
<ul class="socialFeed twitterFeed">
<script type="text/javascript">
var current;
$(function() {
refreshTweets();
});
function refreshTweets() {
$.get("php/tweets.php", function(data){
if(current != data) {
current = data;
$(".socialFeed.twitterFeed").hide().html(data).fadeIn();
}
});
}
setInterval(refreshTweets, 2000);
</script>
</ul>