Skip to content

Instantly share code, notes, and snippets.

@steinbring
Created December 3, 2012 00:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steinbring/4191852 to your computer and use it in GitHub Desktop.
Save steinbring/4191852 to your computer and use it in GitHub Desktop.
How to consume and display RSS in JavaScript
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>How to display RSS via JavaScript</title>
<!-- jQuery CDN -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<script type="text/javascript">
function getRSSFeed(feed){
// Build the YQL query
var qryRSS = 'select * from rss where url='+'"'+feed+'"';
// Initiate the YQL query
$.getJSON("http://query.yahooapis.com/v1/public/yql",
{
// These are the settings for your API call
q: qryRSS,
format: "json"
},
// Take the data you got from the YQL server and output it to the screen. The variable "data" holds the JSON you got back from the YQL server.
function(data) {
// Just bother with the last 4 entries within the JSON feed
for (i=0; i<4; i++)
{
// Output a link, using the link attribute and the title attribute
$('body').append('<a href="'+data.query.results.item[i].link+'">'+data.query.results.item[i].title+'</a><br />');
// Output the description, using the description attribute.
$('body').append(data.query.results.item[i].description);
}
});
};
// Test it with Steinbring.net's RSS Feed
getRSSFeed('http://steinbring.net/feed/');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment