Created
March 19, 2011 19:51
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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+' ...</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