Reputation: 26151
I'm trying to convert RSS to JSON but when I use console in Chrome I get this error
XMLHttpRequest cannot load http://www.blastcasta.com/feed-to-json.aspx?feedurl=http://www.startalkradio.net/?page_id=354. Origin null is not allowed by Access-Control-Allow-Origin.
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>');
});
}
});
Upvotes: 6
Views: 14724
Reputation: 14187
UPDATE: this answer suggests using the Google Feed API which has been deprecated. Other options include Superfeedr: Converting RSS to JSON
That error happens because the RSS file is not in your server, so you are violating the Access-Control-Allow-Origin.
Try this plugin that is used for cross-domain purposes with RSS:
http://jquery-howto.blogspot.com/2009/11/cross-domain-rss-to-json-converter.html
EDIT:
Library download link:
http://code.google.com/p/lomodroid/source/browse/src/functions/jquery.jgfeed.js
Live demo with twitter:
http://jsfiddle.net/oscarj24/NbDWb/
Live demo with the link used in the question:
http://jsfiddle.net/oscarj24/NbDWb/3/
This will convert RSS to 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>
Upvotes: 11
Reputation: 1598
The Google Feeds API can do this easily. Just use the google.feeds.Feed.JSON_FORMAT
result format. Here are the docs for that as well.
Upvotes: 0
Reputation: 24815
Well basically it is really simple. You cannot load that URL because JavaScript/your browser does not allow it. (Because of same origin policy).
You will have to do it with a scripting language (like PHP) or something, but not by JavaScript
Unless you have access to the source (RSS location) and can add headers to allow the origin
Upvotes: 1