gpt4 book ai didi

JQuery 获取多个 RSS 提要

转载 作者:行者123 更新时间:2023-12-01 04:49:46 25 4
gpt4 key购买 nike

如何获取多个 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...

提前致谢

最佳答案

只需循环源 URL 数组

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

关于JQuery 获取多个 RSS 提要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22246473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com