Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<html><head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js">
</script>
<script type="text/javascript">
//Routine to display the items of an RSS feed in a web page
// The output is attached to a uniquely identified HTML item
// The URL of the RSS feed you want to display
var url='http://ouseful.wordpress.com/feed';
//The id of the HTML element you want to contain the displayed feed
var containerID="test";
//------------------------------------------------------
// The gubbins...
function cross_domain_JSON_call(url){
// url points to an RSS feed
url="http://pipes.yahoo.com/ouseful/proxy?url="+encodeURIComponent(url)+"&_render=json&_callback=?";
// displayOutput(url);
//fetch the feed from the address specified in 'url'
// then call "myCallbackFunction" with the resulting feed items
$.getJSON(
url,
function(data) { myCallbackFunction(data.value.items); }
)
}
// A simple utility function to display the title of the feed items
function displayOutput(txt){
$('#'+containerID).append('<div>'+txt+'</div>');
}
function myCallbackFunction(items){
// 'items' contains the separate feed items;
// 'title' contains the item title, 'link' the url, 'description' the main text
// Run through each item in the feed and print out its title
for (var i=0; i < items.length; i++){
displayOutput(items[i].title);
}
// You could easily call 'myArbitraryCallbackFunction(items)" from this function
}
// Tell JQuery to call the feed loader when the page is all loaded
$(document).ready(cross_domain_JSON_call(url));
</script>
</head>
<body>
<div id="test"></div>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.