Reading RSS feed with jQuery?

梦想的初衷 提交于 2019-12-02 21:12:30
Aman Virk

WARNING

The Google Feed API is officially deprecated and doesn't work anymore!

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

Just make sure it points towards an xml file and change the url to 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.

In general you can't retrieve content (in your case an rss feed) from locations different than the current page. 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. That way from the browser's perspective all content comes from the same origin.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!