How to retrieve a cross domain RSS(xml) through Javascript
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() {
// Creat开发者_开发问答e 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);
}
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/");
精彩评论