I have this code in PHP:
<?php
$data = file_get_contents('http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/football/rss.xml');
$xml = simplexml_load_string($data);
echo json_encode($xml);
?>
And this jQuery:
setInterval(function() {
$.getJSON('bbc.php', function(data) {
console.log(data);
$.each(data.channel.item, function(index, item){
$('.container').append("<p data-date='" + item.pubDate + "'>" + item.title + "</p>");
});
});
}, 5000);
So, as you can see, its going to append the same dataset below the previous one creating many duplicated entries. What would be the best approach here, using client or server side, to only send back/display new data, rather than outputting the same data again?
Client side solution:
You can keep global JavaScript array of all rss items. When new item is coming – you check if it’s present in that array, then appent it to the container.