如何通过Javascript检索跨域RSS(xml)
我计划在 Androind 应用程序中显示 Rss feed
我有这个 Rss feed url http://yofreesamples.com/category/free-coupons/feed/ 我无法控制或访问 RSS 源。
JSONP 是使用 JSON 输出响应的请求的解决方案。但在这里,我有 RSS 提要,可以用纯 xml 进行响应。
我有一个限制,不能使用代理来检索 rss 提要。我尝试使用 Google AJAX Feed API 实施,但遇到了问题。我需要获取entry_title的值 它位于回调函数内,并在我的其他函数中使用它,该函数在 android 应用程序内显示系统通知,但我无法获取该值,并且我不想使用任何容器并将其显示在 div 内。 是否有办法获取此值,或者是否有针对此问题的仅限客户端的解决方法
/* ---------------------- 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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我稍微修改了你的代码并且它有效
I modified your code a little and it works