1

我正在使用 jFeed 来解析 RSS 提要,但我现在正在考虑如何在基于间隔的检查中跟踪更改。与之前的加载相比,如何有效地检查提要中是否有新项目?不幸的是,我不能使用 RSS 2.0 last updated 参数,因为它不存在。

4

1 回答 1

1

解决它!请参阅以下解决方案:

//namespace for vars
$.feedentries = { 
    lastKnownEntry : ""
}; 

jQuery.getFeed({
    url: 'proxy.php?url='+encodeURIComponent(url),
    success: function(data) {
        //if new iterate through it until we've found the last know entry
        if(data.items[0].title!==$.feedentries.lastKnownEntry){
            var entries = "";
            $.each(data.items, function(i, feed) {
                if(feed.title!==$.feedentries.lastKnownEntry){
                    entries += '<div class="rss-entry">'+feed.title+'<div class="time"><a href="'+feed.link+'">'+feed.updated+"</a></div></div>\n";
                    //remove last element, prevents from overflowing
                    $(id+" .rss-entry:last-child").remove();
                } else {
                    //stop once we reach last known entry
                    return false;
                }
            });
            //insert into DOM
            $(id).prepend(entries);
            //write new last known rss title
            $.feedentries.lastKnownEntry = data.items[0].title;
        }
    }
});
于 2011-12-13T17:49:09.237 回答