Reading RSS feed using jQuery

佐手、 提交于 2019-12-01 04:32:28

问题


I'm trying to show the title of my latest stumbleupon item using their RSS feed and jquery. The function I have is:

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

Which returns nothing... I just simply want to get a few bits of info about the single latest item in the feed - how can I do this?


回答1:


Here's a tutorial on how to do Cross domain ajax with JQuery.




回答2:


Ólafur Waage gave a good cross site request topic, but there is also another post that actually fits better with your Cross Site RSS reading problem.




回答3:


Here is my little script:

<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>



回答4:


As the previous poster (Waage) mentioned, you are probably doing some Cross-site Scripting which is a security violation on most browsers. What you need to do is create some kind of pass through (the client makes a call to your site, your site downloads another site's content, and returns it to the client).

This is usually pretty easy regardless of whatever server backend you use. It also enables you to do some advanced features with other people's data, like caching.



来源:https://stackoverflow.com/questions/993850/reading-rss-feed-using-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!