使用 jquery/ajax 制作一个简单的 RSS 提要

Making a simple RSS feed with jquery/ajax

本文关键字:一个 简单 提要 RSS jquery ajax 使用      更新时间:2023-09-26

我需要一些帮助,我想制作一个简单的rss提要,从arstechnica这样的网站上读取。在过去的几个小时里,我已经研究并环顾四周,但我对做这样的事情的正确方法有点困惑。我目前正在尝试如何访问 json 数据。这可能是完全错误的,但以下是我到目前为止的示例代码。我感谢你的时间。

<html>
<head>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script>
//rss
function LoadRss()
{
var feed;
$(document).ready(function() {
$.ajax({
    url: "http://feeds.arstechnica.com/arstechnica/index?format=xml",
    dataType: 'xml',
    contentType: 'application/xml',
    success: function(data){
    $('#feed').html(data);
    }
});
});
}
LoadRss()
setInterval( LoadRss, 30000);
</script>
</head>
<body>
    <div id="feed"></div>
</body>
</html>

你不缺少一个参数吗?

contentType: 'application/xml',

请尝试一下。

不要忘记

<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>

所以你可以使用 jQuery.ajax() .

不过,您可能会在CORS跨源方面苦苦挣扎,所以也许您可以使用<iframe>

location.reload()

setInterval(function(){location.reload()}, 30000);

喜欢这个:

<html>
<head>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script>
    setInterval(function(){location.reload()}, 30000);
</script>
</head>
<body>
    <iframe style="width: 800px; height: 800px;" src="http://feeds.feedburner.com/ArsTechnica?format=xml"></iframe>
</body>
</html>

希望这有帮助。