开发者

How to parse rss from a php page, using jQuery/jFeed?

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 =开发者_StackOverflow "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 =)


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


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


In your PHP code, you missed the xml header :

$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);
header("content-type: text/xml"); 
echo "$data";
curl_close($ch);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜