3

I am planing to display Rss feed inside an Androind app

I have this Rss feed url http://yofreesamples.com/category/free-coupons/feed/ I do not have control or access to the RSS feeds.

JSONP is the solution for requests that respond with JSON output. But here, I have RSS feeds which can respond with pure xml .

I have a constraint of not using a proxy to retrieve rss feeds. I tried to implement with Google AJAX Feed API but I ran into a problem. I need to get the value of entry_title which is inside the call back function and use it in my other function which displays a system notification inside the android app , but I am unable to get the value and I dont want to use any containers and display it inside a div. Is there a way to get this value or Is there a client-only workaround for this problem

/* ---------------------- global variables ---------------------- */
var entry;
/* ---------------------- end global variables ---------------------- */
    function getRss(url){ 

    if(url == null) return false;

    google.load("feeds", "1");

    // Our callback function, for when a feed is loaded.
    function feedLoaded(result) {
        if (!result.error) {
            // Check out the result object for a list of properties returned in each entry.
            // http://code.google.com/apis/ajaxfeeds/documentation/reference.html#JSON

            var entry = result.feed.entries[0];             
            var entry_title = entry.title;
        }
        entry = entry_title; // not working

    }


    function Load() {
        // Create a feed instance that will grab feed.
        var feed = new google.feeds.Feed(url);
        // Calling load sends the request off.  It requires a callback function.
        feed.load(feedLoaded);

    }

    google.setOnLoadCallback(Load);             
}

1 Answer 1

2

I modified your code a little and it works

/* ---------------------- global variables ---------------------- */
var entry;
/* ---------------------- end global variables ---------------------- */
function getRss(url){ 

    if(url == null) return false;

    google.load("feeds", "1");

    // Our callback function, for when a feed is loaded.
    function feedLoaded(result) {
        if (!result.error) {
            // Check out the result object for a list of properties returned in each entry.
            // http://code.google.com/apis/ajaxfeeds/documentation/reference.html#JSON

            entry = result.feed.entries[0];             
        }
        // pass it to other function
        someFunction(entry.title);
    }

    function Load() {
        // Create a feed instance that will grab feed.
        var feed = new google.feeds.Feed(url);
        // Calling load sends the request off.  It requires a callback function.
        feed.load(feedLoaded);
    }

    // some function
    function someFunction(s) {
        alert(s);
    }

    google.setOnLoadCallback(Load);             
}

// calling it ?
getRss("http://yofreesamples.com/category/free-coupons/feed/");
Sign up to request clarification or add additional context in comments.

3 Comments

thanks mike. Is there a way to pass the value to a global variable because , I want to use the value in a different js file and do some checking with the variable.
What if someFunction is in another JS file. Is it possible to still pass the value?
sure, but you have to make sure that the other JS file that contains someFunction is included first so it would load first. or, add the call getRSS when the first JS file is loaded. check api.jquery.com/jQuery.getScript

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.