开发者

process RSS feeds with AJAX and javascript only

Is it possible to connect to an RSS feed, retrieve the XML o开发者_运维百科bject then parse and display it all within client side javascript/ AJAX?

Thanks,


Subject to the Same Origin Policy, yes. http://www.xml.com/lpt/a/1672 has an example (although, frankly, the code isn't very good, you starting hitting global variables in the first function).


It is technically possible.

However, there are some limitations on the browser side : AJAX requests (XHR / XmlHttpRequest) can only be done on the same domain that hosts your javascript script(s).

It means that a script hosted on http://example.com/ cannot perform a XHR on http://domain.com/.

You can bypass this limitation by using a proxy script server-side. E.g: http://example.com/getFeed.php?feed=the_complete_url_of_the_targeted_feed


Yep, certainly possible. A real world example follows:

<div id='tagged'></div>

<script type="text/javascript">

 $.get('http://stackoverflow.com/feeds/user/40986', function(data){
     $(data).find('entry').each(function(){
         var $rssLink = $('<a></a>')
             .attr('href', $(this).find('link').attr('href'))
             .append($(this).find('id').text());
         var $divContainer = $('<div></div>');
         $rssLink.appendTo($divContainer);
         $divContainer.appendTo('#tagged');
     });
 });

</script>

Using jQuery I get my own StackOverflow rss feed and print out a link to each entry.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜