Tag Archives: JSON

02Dec/12

How to easily consume and display RSS in JavaScript

I came across this issue a few years ago and just recently found a good solution.  JavaScript has the ability to make an AJAX request to whatever page you want, and return the result.  The problem is that the same origin policy, enforced by most browsers, won’t allow you to return most content if it originates from outside of your domain.  So, if your JavaScript is at http://steinbring.net/js/example.js, it would not be able to grab and display http://news.ycombinator.com/rss.

So, how do you get around the same origin policy?  You can get around it by targeting a remote JSON file.  JSON isn’t subject to the same origin policy.  A lot of solutions involve running a local, server-side proxy. The proxy receives a URL, fetches the XML output, and returns a JSON output to the JavaScript.

So, how can you use this proxy method without having to maintain a server-side proxy?  You can use the Yahoo! Query Language.  It is a set of free, public APIs that includes an endpoint for converting RSS to JSON.  So, how do we use it?