JQuery获取多个RSS源

时间:2014-03-07 09:40:39

标签: jquery rss

我如何获取多个RSS源并将其显示在每个源的Div中?

这样的事情几乎可以做到,但我不知道如何获取多个RSS源:

$(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);
 }
});
});

我想要一个这样的结构:

<div id="bbc">BBC rss feeds here</div>
<div id="dailyMail">daily Mail rss feeds here</div>
etc...etc...

提前致谢

1 个答案:

答案 0 :(得分:1)

只需遍历源网址数组

$(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);
            }
        });
    }
});