本文介绍了用 jQuery 阅读 RSS 提要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 jQuery rss 插件 jFeed,并使用他们的示例代码在他们的网站上,我创建了以下似乎不起作用的代码:

Using the jQuery rss pluging jFeed, and using their example code on their website, I have created the following code which does not seem to work:

jQuery.getFeed({
    url: 'http://www.hotukdeals.com/rss/hot',
    success: function(feed) {
        alert(feed.title);
    }
});

我收到一条消息:

XMLHttpRequest cannot load http://www.hotukdeals.com/rss/hot. Origin http://intranet is not allowed by Access-Control-Allow-Origin.

有人知道我为什么会收到此访问控制消息吗?这个 rss 提要在我的桌面和在线 rss 阅读器中运行良好...

Anyone know why I am getting this access control message? This rss feed works fine in my desktop and online rss readers...

推荐答案

警告

Google Feed API 已正式弃用不再工作了

无需插件即可轻松完成,返回数据为json格式

It can be done very easily without a plugin and the returned data would be in json

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

只要确保它指向一个 xml 文件并将 url 更改为 url Rss feed,

Just make sure it points towards an xml file and change the url to url Rss feed,

这篇关于用 jQuery 阅读 RSS 提要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-17 09:22