Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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];
                    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);
share|improve this question
    
It becouse your programming skill level ... First data.responseData can be != 200 or data.responseData.feed == null ... Second return statment in function(data) will not return in from function getRss ... –  Selvin Aug 3 '11 at 16:18
    
yes i know but my question was when I do a console.log(title); I am not able to see the output. I am still learning javascript thanks for explaining about the data.responseData. But is nt it == 200 in my case. –  Yeshwanth Venkatesh Aug 3 '11 at 16:27
    
Becouse console.log(title) is never called ... why ... It's hard to say without testdata console output ... –  Selvin Aug 3 '11 at 16:34
    
Can I use jfeed instead !! –  Yeshwanth Venkatesh Aug 3 '11 at 16:41
add comment

1 Answer

up vote 1 down vote accepted

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 
share|improve this answer
    
thanks for pointing it out. But I am still not getting the output when I do a console.log(title); –  Yeshwanth Venkatesh Aug 3 '11 at 16:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.