I want to read an rss feed converted to json format with a google api ; i had put some alerts but i can’t see them when i run my page ! Why ?
Here is my jQuery code :
function getFeed(url){
$('#screen #content').html("");
$.ajax({
url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q='+url,
crossDomain: true,
dataType: 'json',
success: function(data) {
alert(3);
$.each(data.entries, function(i,results){
alert(1);
});
}
});
}
getFeed('http://www.nytimes.com/services/xml/rss/nyt/Science.xml');
Thanks !
Ajax requests are limited by the browser’s Same Origin Policy. You can’t talk directly to a server via ajax that isn’t on the same domain as the page your script is running in.
So, you need to use the jsonp feature from jquery ajax:
dataType: ‘jsonp’ is the keyword here.
You can read more about it searching ‘jsonp’ here:
http://api.jquery.com/jQuery.ajax/
or here:
http://bob.ippoli.to/archives/2005/12/05/remote-json-jsonp/