问题
How can I fetch multiple RSS sources and display them in lets say a Div
for each source?
Something like this would almost do it, but I dont know how to feetch multiple RSS sources:
$(function(){
url = 'http://www.thetutlage.com/rss.xml';
$.ajax({
type: "GET",
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(url),
dataType: 'json',
error: function(){
alert('Unable to load feed, Incorrect path or invalid feed');
},
success: function(xml){
values = xml.responseData.feed.entries;
console.log(values);
}
});
});
I want a structure like this:
<div id="bbc">BBC rss feeds here</div>
<div id="dailyMail">daily Mail rss feeds here</div>
etc...etc...
thanks in advance
回答1:
Just loop trough array of source urls
$(function () {
var urls = ['http://www.thetutlage.com/rss.xml', 'example.net', 'another.example.net'];
for (var i = 0; i < urls.length; i++) {
$.ajax({
type: "GET",
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(urls[i]),
dataType: 'json',
error: function () {
alert('Unable to load feed, Incorrect path or invalid feed');
},
success: function (xml) {
values = xml.responseData.feed.entries;
console.log(values);
}
});
}
});
来源:https://stackoverflow.com/questions/22246473/jquery-fetch-multiple-rss-feeds