2011-12-13 73 views
1

我正在使用jFeed來解析RSS訂閱源,但我現在想如何跟蹤基於時間間隔的檢查的更改。如何有效地檢查Feed中是否有新項目與之前的負載相比較?不幸的是,我不能使用RSS 2.0上次更新的參數,因爲它不存在。如何在jQuery中加載新的rss訂閱源項目

回答

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; 
     } 
    } 
});