简体   繁体   English

用jQuery阅读RSS feed?

[英]Reading RSS feed with jQuery?

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 rss插入jFeed ,并在他们的网站上使用他们的示例代码,我创建了以下代码似乎不起作用:

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

I get a message saying: 我收到一条消息说:

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

Anyone know why I am getting this access control message? 任何人都知道为什么我得到这个访问控制消息? This rss feed works fine in my desktop and online rss readers... 这个rss feed在我的桌面和在线RSS阅读器中运行良好...

WARNING 警告

The Google Feed API is officially deprecated and doesn't work anymore ! Google Feed API已正式弃用不再有效

It can be done very easily without a plugin and the returned data would be in json 没有插件就可以很容易地完成它,返回的数据将在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);
        }
    });
    });

Just make sure it points towards an xml file and change the url to url Rss feed, 只需确保它指向xml文件并将url更改为url Rss feed,

Your failing because of the same origin policy of JavaScript, which basically restricts you in the locations you can retrieve and manipulate files from. 您的失败是因为JavaScript的原始策略相同 ,这基本上限制了您可以从中检索和操作文件的位置。

In general you can't retrieve content (in your case an rss feed) from locations different than the current page. 通常,您无法从不同于当前页面的位置检索内容(在您的情况下是rss订阅源)。 Exceptions are just images and scripts. 例外只是图像和脚本。

So one solution in your case may be to set up a proxy script on your server, which just calls the RSS feed and relays the results to your page. 因此,您的案例中的一个解决方案可能是在您的服务器上设置代理脚本,该脚本只调用RSS源并将结果中继到您的页面。 That way from the browser's perspective all content comes from the same origin. 从浏览器的角度来看,所有内容都来自同一个来源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM