I'm trying to implement a few feeds into my site using a div-populating function. Previously, I had identical JavaScript code blocks through my page (one for each feed), but in the interest of being a good (or better) coder, I decided to stick the repetitive code into an external script file and run it with varying parameters instead.
Unfortunately, the feeds refuse to load with my new implementation, and I'm running out of ideas. I structured my callback function based on user ndp's interesting suggestions in question 9662168.
So, I have the following two functions in my external script file (minor code redaction for simplicity):
function populateRSSFeed(divID) {
var targetDiv = document.getElementById(divID);
return function callback(result) {
if (!result.error) {
var container = document.getElementById(targetDiv);
var list = document.createElement('ul');
<snip: div-population code here>
container.appendChild(list);
}
else
alert('Error fetching feeds!');
}
}
function initializeRSSFeed(callback, targetFeed) {
google.load('feeds','1');
var feed = new google.feeds.Feed(targetFeed);
var numEntries = 3;
feed.setNumEntries(numEntries);
feed.load(callback);
}
These functions are called as follows in my HTML:
<script>
var callback = populateRSSFeed('feed-list-wrapper-1');
initializeRSSFeed(callback, 'http://rss.cnn.com/rss/cnn_topstories.rss');
</script>
The error message I'm receiving makes me think that something is going wrong at the feed-loading stage, but I can't determine the cause.
Uncaught TypeError: Cannot read property 'Feed' of undefined
What do you guys think?