JQuery Fetch Multiple RSS feeds

隐身守侯 提交于 2019-12-13 02:25:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!