duanshan1977 2010-03-12 17:01
浏览 45
已采纳

如何使用jQuery / jFeed从php页面解析rss?

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 =)

  • 写回答

3条回答 默认 最新

  • doujiangao4229 2010-03-12 17:06
    关注

    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);
           }
       });
    ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误