views:

303

answers:

2

I'm trying to fumble my way through parsing rss sensibly, using jQuery and jFeed.

Because of the same origin policy I'm pulling the BBC's health news feed into a local page (http://www.davidrhysthomas.co.uk/play/proxy.php).

Originally this was just the same proxy.php script as available in the jFeed download package, but due to my host's disabling allow_url_fopen() I've amended the php to the following:

$url = "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/health/rss.xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);

echo "$data";
curl_close($ch);

Which seems to generate the same/comparable contents as the original fopen on my local machine.

Now that seems to be working, I'm looking at setting the jFeed script up to work with the page and, to my embarrassment, don't see how.

I understand that, at the least, this should work:

jQuery.getFeed({
   url: 'http://www.davidrhysthomas.co.uk/play/proxy.php',
   success: function(feed) {
      alert(feed.title);
   }
});

...but, as I'm sure you anticipate, it doesn't. What non-output there is, is available for your perusal here: http://www.davidrhysthomas.co.uk/play/exampleTest.html. And I honestly don't have a clue what to do about it.

If anyone could offer some pointers, tips, hints, or, at a pinch, a quick slap around the cheeks and a 'pull yourself together!' it'd be much appreciated...

Thanks in advance =)

+1  A: 

On your test page, you have some lines of script that look like wrong...

<script type="text/javascript">

jQuery(function() {

   url: 'http://www.davidrhysthomas.co.uk/play/proxy.php',
   success: function(feed) {
      alert(feed.title);
   }
...

I think that should be more like...

<script type="text/javascript">

jQuery(function() {

   jQury.ajax( {
       url: 'http://www.davidrhysthomas.co.uk/play/proxy.php',
       success: function(feed) {
           alert(feed.title);
       }
   });
...
Sohnee
That didn't work, as such, but, on the bright side, the alert box now pops up! That's gotta be progress...even if all I'm getting is 'undefined.' +1 for the start, though, thanks!
David Thomas
Glad it helped - maybe just alert(feed) to see what you're starting with!
Sohnee
+1  A: 

The Zend Framework has a class for consuming all kinds of feeds.

it's called Zend_Feed

http://framework.zend.com/manual/en/zend.feed.html

Joshua Smith
Sadly, though unsurprisingly, given that `allow_url_fopen()` is disallowed, it seems that I don't have access to the Zend framework on my current host. Though I'm considering downloading it to my local machine for learning purposes, but I'd rather not switch hosts unless absolutely necessary. Thanks though, +1 for an interesting link. =)
David Thomas