8

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

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...

oshirowanen
  • 15,297
  • 82
  • 198
  • 350
  • 1
    http://stackoverflow.com/questions/9327218/access-control-allow-origin-not-allowed-by – exaptis Jul 05 '12 at 14:59
  • 1
    This problem is mind-boggling to me. Aren't news feeds meant specifically to be read from other domains? Why does the browser block this? Why do sites even offer RSS feeds, if the web browser does not allow reading them? – Kokodoko Dec 16 '14 at 16:41
  • If you are using Chrome , try the extension [Allow-Control-Allow-Origin](https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi) – vanduc1102 May 31 '15 at 16:32

2 Answers2

31

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,

B 7
  • 670
  • 7
  • 23
Aman Virk
  • 3,909
  • 8
  • 40
  • 51
  • with this technique, how do we also receive other element values like , , , that may be within each rss block? It that possible? This will only load the default elements that google expects to read, but my rss file has custom element names... – klewis Aug 15 '13 at 15:32
  • i tried doing it, and within success: function(data), it only searches and loads for the following elements - , , ,, , , . But it is not loading or finding <company> <careertype> or any other custom element within this rss block, which is there when you look at the actual rss file itself. Just looking for ideas...</careertype></company> – klewis Aug 15 '13 at 15:51
  • can i have a link to your rss feed – Aman Virk Aug 15 '13 at 15:58
  • this is it - http://www.agcareers.com/publisher/ffa/food-products-processing-systems.cfm – klewis Aug 15 '13 at 16:02
  • 1
    The google feed api has been deprecated and was shut down on the 02.12.2015 – Mido Dec 04 '15 at 13:12
  • Only answer that worked for me in a bunch of stackoverflow posts. Thanks. – shell Mar 08 '16 at 22:28
1

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.

Sirko
  • 72,589
  • 19
  • 149
  • 183
  • i have just posted an answer which will let you pull feeds from cross domain without any same origin policy issue. I have tried it in all the browsers and seems to be working fine.... – Aman Virk Jul 05 '12 at 15:28
  • 1
    @AmanVirk You're using a proxy script to generate a JSONP request. It will work fine as long as this google api is online, but will fail without it. – Sirko Jul 05 '12 at 15:31
  • @AmanVirk. I disagree, I think if I develop my own proxy script on my own server, that server is more likely to go offline than a google api... So I think it is more reliable for me to use the Google Api, especially as I don't have much time and even more especially that this RSS feed is not critical. So it being offline everyone now and again is not a big deal. – oshirowanen Jul 06 '12 at 09:02
  • @Sirko. I disagree, I think if I develop my own proxy script on my own server, that server is more likely to go offline than a google api... So I think it is more reliable for me to use the Google Api, especially as I don't have much time and even more especially that this RSS feed is not critical. So it being offline everyone now and again is not a big deal. – oshirowanen Jul 06 '12 at 09:03
  • @oshirowanen In my opinion I try to be as independent as possible from foreign services with my pages as possible. Depends on the specific use case, however. – Sirko Jul 06 '12 at 09:07