2011-08-03 34 views
3

我刨,以显示内部的Androind应用如何通过JavaScript

我有这样的RSS提要URL http://yofreesamples.com/category/free-coupons/feed/ 我没有控制或访问RSS RSS订阅检索跨域RSS(XML)饲料。

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);    
} 

回答

2

我修改你的代码一点点仅客户端的解决方法和它的作品

/* ---------------------- 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/"); 
+1

感谢麦克。有没有办法将值传递给全局变量,因为我想在不同的js文件中使用该值,并使用变量进行一些检查。 –

+1

如果someFunction在另一个JS文件中,该怎么办?是否有可能仍然通过价值? –

+1

当然,但你必须确保包含someFunction的其他JS文件首先被包含,因此它将首先加载。或者,在加载第一个JS文件时添加调用getRSS。检查http://api.jquery.com/jQuery.getScript/ –