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

发布于 2024-08-25 03:03:29 字数 1747 浏览 10 评论 0原文

我试图使用 jQuery 和 jFeed

由于同源政策< /a> 我正在将 BBC 的健康新闻推送到本地页面 (http://www.davidrhysthomas .co.uk/play/proxy.php)。

最初,这与 jFeed 下载包中提供的 proxy.php 脚本相同,但由于我的主机禁用 allow_url_fopen(),我已将 php 修改为以下内容:

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

这似乎在我的本地计算机上生成了与原始 fopen 相同/相似的内容。

现在这似乎有效,我正在考虑设置 jFeed 脚本以与该页面一起使用,但令我尴尬的是,我不知道如何操作。

我知道,至少,这应该有效:

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

...但是,正如我确信您所预料的那样,它不起作用。有哪些非输出可供您仔细阅读:http://www.davidrhysthomas.co.uk/play/ exampleTest.html。老实说,我不知道该怎么办。

如果有人可以提供一些指示、技巧、提示,或者在紧要关头,快速拍打你的脸颊并说“振作起来!”非常感谢...

提前致谢 =)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南街女流氓 2024-09-01 03:03:29

在您的测试页上,您有一些脚本行看起来像是错误的...

<script type="text/javascript">

jQuery(function() {

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

我认为这应该更像是...

<script type="text/javascript">

jQuery(function() {

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

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);
       }
   });
...
君勿笑 2024-09-01 03:03:29

Zend Framework 有一个用于使用各种提要的类。

它称为 Zend_Feed

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

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

随风而去 2024-09-01 03:03:29

在您的 PHP 代码中,您错过了 xml 标头:

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文