2011年5月6日 星期五

get google ajax feed ues JSONP

function get_rss_feeds(){
 
 var JSONP = document.createElement("script") ;
 
 var url=escape($('#add_new_subscript_txt').val());
   
    JSONP.onload = JSONP.onreadystatechange = function(){
     
     if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
     
      JSONP.onload = JSONP.onreadystatechange = null
     }
    }
    JSONP.type = "text/javascript";
    JSONP.src = ""https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q="+url+"&callback=foo&output=json_xml&num=0;
   
    document.getElementsByTagName("head")[0].appendChild(JSONP);
 
 //alert($('#add_new_subscript_txt').val());   
}
function foo(rss) {
 if(rss.responseStatus==400){
  showError('InvalidFeedAddress');
 }
 
 if(rss.responseStatus==200){
  
  $('#rss_add_subscription').dialog('close');
  
  var xml=$('<xml>'+rss.responseData.xmlString+'</xml>');
  
  var image=xml.find("url").text();
  
 
  
  
  if(image==''){
   image='wd_nas/images/rss_icon.png';
  }
  
  add_rss_feed(rss.responseData.feed.feedUrl,rss.responseData.feed.title,rss.responseData.feed.description,image);
  
  
  
 }
 
 
    
}

為什麼要這樣做咧? 因為我不是放在網站上的,所以沒有domaim name只有ip而已,所以無法用key去接到feeds,參考了一些網站做出來的。

沒有留言:

張貼留言