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>');
});
}
});
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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With