繁体   English   中英

该插件如何读取RSS提要而不会出现跨域问题?

[英]How this plugin can read RSS feeds without cross-domain issue?

我已经将此插件部署在本地服务器上http://jquery-plugins.net/FeedEk/FeedEk.html

它可以工作,但是我看不到任何php脚本:没有跨域问题怎么办?

它使用谷歌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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM