游.程 2018-03-04 19:09 采纳率: 0%
浏览 34

在jQuery中阅读RSS feed

I'm attempting to learn some web development by trying to read an RSS feed and then displaying the output on a single web page.

Currently when I attempt to read the RSS feed, I receive an error message:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.URL.com/rss.php?secret_key=*******&feedtype=download&timezone=0&showrows=50&categories=53,3,5. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Reading a similar post here, I thought the answer would be to add the header as shown in my code below but that doesn't work.

Any ideas why I'm receiving this error and how to resolve it?

code:

<!DOCTYPE html>
<html>
<head>
    <title>RSS Reader</title>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    </head> 
</head>

<script>
$(document).ready(function() {

    //feed to parse
    var feed = "https://www.URL.com/rss.php?secret_key=*******&feedtype=download&timezone=0&showrows=50&categories=53,3,5";

    $.ajax(feed, {
        accepts:{
            xml:"application/rss+xml"
        },
        dataType:"xml",
        headers: {
            "Access-Control-Allow-Headers":"x-requested-with"
        },
        success:function(data) {

        $(data).find("item").each(function () {
            var el = $(this);
            console.log("------------------------");
            console.log("title      : " + el.find("title").text());
            console.log("link       : " + el.find("link").text());
            console.log("description: " + el.find("description").text());
        });
        }
    });
});

</script>

<body>
    this is a test page
</body>
</html>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭