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

馋奶兔 提交于 2019-12-12 05:09:56

问题


I have deployed this plugin on my local server http://jquery-plugins.net/FeedEk/FeedEk.html

It works but I can't see any php script : how can it work without cross-domain issue ?


回答1:


It uses google api which can crossdomain everything =)

http://ajax.googleapis.com/ajax/services/feed/load?....

take a look at yql

var yql=function(a,b){
 return 'http://query.yahooapis.com/v1/public/yql?q='+
 encodeURIComponent('select * from '+b+' where url=\"'+a+'\"')+
 '&format=json';
};

usage

var crossdomainurl=yql(url,(xml,json,html,feed,rss...))

returns the crossdomain url for (xml,json,html,feed,rss...)

now you can use xhr without any problem

the xhr.response returns always a json in this case.

Full Example:

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



回答2:


Skimming the source code shows that it uses a 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=?",


来源:https://stackoverflow.com/questions/18302852/how-this-plugin-can-read-rss-feeds-without-cross-domain-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!