0

Is it possible to connect to an RSS feed, retrieve the XML object then parse and display it all within client side javascript/ AJAX?

Thanks,

test
  • 23
  • 2
  • 7
  • Is there a specific reason why it all should have to be client side? A piece of Javascript can easily call a script on the server to do that work and then pass back the results to the piece of Javascript. – Niels Bom Jan 28 '10 at 13:27
  • I prefer to do it all client side for debugging without deploying to the server – test Jan 28 '10 at 13:30
  • http://stackoverflow.com/questions/226663/parse-rss-with-jquery – s-sharma Jan 28 '10 at 13:44

3 Answers3

0

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

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • So this would effectively be able to consume a feed ONLY on the same domain? – test Jan 28 '10 at 13:34
  • In a standard security context — yes. You can proxy things through your own server, of course. – Quentin Jan 28 '10 at 13:54
  • @Dhaivat — the question does not mention Phonegap. Are you confusing this question with [the entirely separate one that you asked](http://stackoverflow.com/questions/6483804/phonegap-rss-feeds-javascript)?! – Quentin Jun 26 '11 at 12:24
  • I'm really sorry, I've been commenting on the wrong answers in the wrong question. – Dhaivat Pandya Jun 26 '11 at 12:25
0

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

OcuS
  • 5,320
  • 3
  • 36
  • 45
0

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.

Naeem Sarfraz
  • 7,360
  • 5
  • 37
  • 63
  • I would like more explanation, considering that others are saying this isn't possible due to the XHR rules. I copy/pasted your code onto a test site just now, changing the URL, and didn't get results. – Ziggy Mar 08 '13 at 07:36