[英]How this plugin can read RSS feeds without cross-domain issue?
它使用谷歌API可以跨域一切=)
http://ajax.googleapis.com/ajax/services/feed/load?....
看看yql
var yql=function(a,b){
return 'http://query.yahooapis.com/v1/public/yql?q='+
encodeURIComponent('select * from '+b+' where url=\"'+a+'\"')+
'&format=json';
};
用法
var crossdomainurl=yql(url,(xml,json,html,feed,rss...))
返回(xml,json,html,feed,rss ...)的跨域网址
现在您可以毫无问题地使用xhr
在这种情况下,xhr.response始终返回json。
完整示例:
var x=function(a,b,c){c=new XMLHttpRequest;c.open('GET',a);c.onload=b;c.send()},
yql=function(a,b){return 'http://query.yahooapis.com/v1/public/yql?q='+encodeURIComponent('select * from '+b+' where url=\"'+a+'\"')+'&format=json';};
x(yql('PUTFEEDURLHERE','xml'),function(){console.log(JSON.parse(this.response))})
略过源代码表明它使用了JSON-P API。
url: "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=" + def.MaxCount + "&output=json&q=" + encodeURIComponent(def.FeedUrl) + "&hl=en&callback=?",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.