Skip to content

Instantly share code, notes, and snippets.

@paulusm
Last active March 8, 2016 10:35
Show Gist options
  • Save paulusm/804c96b2daac82f8fb65 to your computer and use it in GitHub Desktop.
Save paulusm/804c96b2daac82f8fb65 to your computer and use it in GitHub Desktop.
var feed = "http://info.uwe.ac.uk/news/xml/uwenewsrss.xml";
var api = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=displayFeed&output=json&q=" + encodeURIComponent(feed);
//This creates a script element to make a "jsonp" request each time the page is requested
var script = document.createElement('script');
script.src = api;
document.getElementsByTagName('head')[0].appendChild(script);
//use the data that comes back to put into the HTML div
var displayFeed = function(data){
// loop through the feed items
if(data.responseData.feed.entries){
for(var i=0; i< data.responseData.feed.entries.length; i++){
//create new HTML elements to hold the items
var hl = document.createElement("li");
var lnk = document.createElement("a");
var blurb = document.createElement("p");
// make a link and add it to the list item
lnk.href = data.responseData.feed.entries[i].link;
lnk.innerText = data.responseData.feed.entries[i].title;
lnk.text = data.responseData.feed.entries[i].title;
hl.appendChild(lnk);
// Also add the content snippet
blurb.textContent= data.responseData.feed.entries[i].contentSnippet;
blurb.innerText= data.responseData.feed.entries[i].contentSnippet;
console.log(blurb);
hl.appendChild(blurb);
//Add the whole item to the list
document.getElementById("hls").appendChild(hl);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment