Problem parsing Rss feed using javascript
I am trying to read two Rss feed urls at regular intervals and display the latest feed title as a notification inside my android app.
As the setinterval function is being called every 8000 ms I want to make sure there are no duplicate notifications of the same title.
When I do a console.log inside the getrss function I am able to see the xml object, but I am not able to see any data being outputted for var xml , var entry or var title . Plese point out were I might be going on.
/* ---------------------- global variables ---------------------- */
var Rss1_title;
var Rss2_title;
/* ---------------------- end global variables------------------- */
/* --------- pull latest Rss feed title for first url: ---------- */
function update_rss1_feeds(){
var new_title = getRss("http://yofreesamples.com/category/real-freebies/feed/");
if(Rss1_title != new_title)
//display the notification
navigator.notification.alert(
new_title, // message
'New Rss Entry', // title
'New Rss Entry' // buttonName
);
Rss1_title = new_title;
}
/* --------- end : --------- */
/* --------- pull latest Rss feed title for second url: --------- */
function update_rss2_feeds(){
var new_title = getRss("http://yofreesamples.com/category/free-coupons/feed/");
if(Rss2_title != new_title)
//display the notification
navigator.notification.alert(
new_title, // message
'New Rss Entry', // title
'New Rss Entry' // buttonName
);
Rss2_title = new_title;
}
/* --------- end : --------- */
This is the getrss function were I parse the Rss feed. I might be doing something wrong over here.
function getRss(url){
if(url == null) return false;
// Create Google Feed API address
var api = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=" + encodeURIComponent(url);
api += "&output=json_xml"
var newEntry;
// Send request
$.getJSON(api, function(data){
console.log('testdata',data); // the response is xmlobjest
// Check for error
if (data.responseStatus == 200) {
var feeds = data.responseData.feed;
if (!feeds) {
return false;
}
// Get XML data for media (parseXML not used as requires 1.5+)
var xml = getXMLDocument(data.xmlString);
var xmlEntries = xml.getElementsByTagName('item');
var entry = feeds.entries[0];
开发者_Python百科 var title = entry.title;
console.log('test',title); // it is not being displayed , it seems its not going inside the if statement
return title;
}else {
};
});
}
This is the Function call.
setInterval('update_rss1_feeds()',7000);
setInterval('update_rss2_feeds()',8000);
When I access:
http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=[an rss feed url]&output=json_xml
I get an error "bad or missing callback or context", if I take our the callback parameter it works fine
http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=[an rss feed url]&output=json_xml
精彩评论