2009-06-14 111 views
4

我試圖用他們的RSS提要和jQuery顯示我最新的stumbleupon項目的標題。 我所擁有的功能是:使用jQuery閱讀RSS提要

function get_stumbleupon() { 
    $.get("http://rss.stumbleupon.com/user/fredkelly/", function(data) { 
     alert(data.title); 
    }, "xml"); 
} 

它返回沒什麼......我只是單純的想獲得關於飼料中的最新項目信息的數位 - 我該怎麼辦呢?

回答

4

Here's a tutorial關於如何使用JQuery跨域ajax。

+0

在該教程請務必按照鏈接到「通用RSS到JSON轉換器」。 – Josh 2010-12-01 15:20:26

0

正如前面的海報(Waage)提到的,你可能正在做一些跨站腳本,這是大多數瀏覽器的安全違規。你需要做的是創建某種傳遞(客戶打電話給你的網站,你的網站下載另一個網站的內容,並將其返回給客戶端)。

無論您使用哪種服務器後端,這通常都很容易。它還使您能夠對其他人的數據執行一些高級功能,例如緩存。

+1

對於那些不熟悉理查德解決方案的人來說,這基本上就是所謂的「代理服務器」。 – jmort253 2011-01-07 21:43:15

1

這裏是我的小腳本:

<script type="text/javascript"> 
jQuery(document).ready(function(){ 
jQuery.ajax({ 
    url: "/feed.xml", // RSS url 
    success: function(msg){ 
    jQuery('#blip').html(''); // where to put RSS 
    jQuery('entry',msg).slice(0,3).each(function(){ // slice: get only first 3 posts 
     var html = '<div>'; 
     var upd = jQuery('updated', this).text().replace(/[TZ]/g, ' '); 
     var upd = jQuery.trim(jQuery('updated', this).text()); 
     upd = upd.replace(/-/g,"/").replace(/T/," ").replace(/Z/," UTC"); 
     upd = upd.replace(/([\+-]\d\d)\:?(\d\d)/," $1$2"); 
     updf = new Date(upd).toLocaleString(); 
     html += '<p class="post_date">' + updf + '</p>'; 
     html += '<div class="post_content"><span>' + jQuery('content', this).text() + '</span></div>'; 
     html += '</div>'; 
     jQuery(html).appendTo('#blip'); 
    }); 
    }, 
    error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown);} 
}); 
}); 
</script>