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,

3
  • 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. Commented Jan 28, 2010 at 13:27
  • I prefer to do it all client side for debugging without deploying to the server Commented Jan 28, 2010 at 13:30
  • stackoverflow.com/questions/226663/parse-rss-with-jquery Commented Jan 28, 2010 at 13:44

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

4 Comments

So this would effectively be able to consume a feed ONLY on the same domain?
In a standard security context — yes. You can proxy things through your own server, of course.
@Dhaivat — the question does not mention Phonegap. Are you confusing this question with the entirely separate one that you asked?!
I'm really sorry, I've been commenting on the wrong answers in the wrong question.
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

Comments

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.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.