Skip to content

Instantly share code, notes, and snippets.

@cherrypj
Created March 19, 2011 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cherrypj/877756 to your computer and use it in GitHub Desktop.
Save cherrypj/877756 to your computer and use it in GitHub Desktop.
Using jQuery to grab a same-domain XML feed and insert into HTML
<script src="jquery.js"></script>
<script>
$(function(){
// Grab an XML feed
var end=0;
function get_RSS(feedurl,feeddiv){
$.ajax({
type: "GET", url: feedurl, dataType: "xml", success: function(xml){
$(xml).find("item").each(function(i){
var title = $(this).find("title").text();
//title = title.substring(0, 150);
//var space = title.lastIndexOf(' ');
//title = title.substring(0, space);
var itemlink = $(this).find("link").text();
html = '<li><a href="'+itemlink+'">'+title+'&nbsp;...</a></li>';
$(feeddiv).html(html);
if (i == end) { return false; }
});
}
});
}
get_RSS("feed.xml","#feed");
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment