我正在尝试将RSS转换为JSON但是当我在Chrome中使用控制台时,我收到此错误
XMLHttpRequest无法加载 http://www.blastcasta.com/feed-to-json.aspx?feedurl=http://www.startalkradio.net/?page_id=354.Access-Control-Allow-Origin不允许使用null.
jQuery的:
$(document).ready(function() {
var rss_url = "http://www.blastcasta.com/feed-to-json.aspx?feedurl=http://www.startalkradio.net/?page_id=354";
$.ajax({
type : 'GET',
url : rss_url,
succces : function(data) {
$.each(data.rss, function(i, item) {
$("#results").append('<ul>' + item.channel.item.description + '</ul>');
});
},
dataType : 'json',
async : true
});
function fetchRss(data) {
$.each(data.rss, function(i, item) {
$("#results").append('<ul>' + item.channel.item.description + '</ul>');
});
}
});
Run Code Online (Sandbox Code Playgroud)
Osc*_*car 11
更新:此答案建议使用已弃用的Google Feed API.其他选项包括Superfeedr:将RSS转换为JSON
发生该错误是因为RSS文件不在您的服务器中,因此您违反了Access-Control-Allow-Origin.
尝试使用此插件用于RSS的跨域目的:
http://jquery-howto.blogspot.com/2009/11/cross-domain-rss-to-json-converter.html
编辑:
图书馆下载链接:
http://code.google.com/p/lomodroid/source/browse/src/functions/jquery.jgfeed.js
使用twitter进行现场演示:
http://jsfiddle.net/oscarj24/NbDWb/
使用问题中使用的链接进行现场演示:
http://jsfiddle.net/oscarj24/NbDWb/3/
这会将RSS转换为JSON
<script src="jquery.js"></script>
<script src="jquery.jgfeed.js"></script>
<script>
$.jGFeed('http://twitter.com/statuses/user_timeline/26767000.rss',
function(feeds){
// Check for errors
if(!feeds){
// there was an error
return false;
}
// do whatever you want with feeds here
for(var i=0; i<feeds.entries.length; i++){
var entry = feeds.entries[i];
// Entry title
entry.title;
}
}, 10);
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11909 次 |
| 最近记录: |