使用jQuery.get()读取RSS提要的问题

时间:2022-12-22 01:56:16

I've been pulling my hair out trying to use jQuery.get() to pull in my dynamically generated RSS feed and I'm having nothing but issues, is my RSS feed the wrong format? If so can I convert it to the correct format using javascript?

我一直在努力使用jQuery.get()来引入我的动态生成的RSS提要,而我只有问题,我的RSS提供格式错误了吗?如果是这样我可以使用javascript将其转换为正确的格式?

Here's my feed: http://dev.chriscurddesign.co.uk/burns/p/rc_rss.php?rcf_id=0

这是我的饲料:http://dev.chriscurddesign.co.uk/burns/p/rc_rss.php?rcf_id = 0

Here's my code:

这是我的代码:

function get_rss_feed() {

        $(".content").empty();

        $.get("http://dev.chriscurddesign.co.uk/burns/p/rc_rss.php?rcf_id=0", function(d) {

            var i = 0;
            $(d).find('item').each(function() {

                var $item = $(this);
                var title = $item.find('title').text();
                var link = $item.find('link').text();
                var location = $item.find('location').text();
                var pubDate = $item.find('pubDate').text();

                var html = '<div class="entry"><a href="' + link + '" target="_blank">' + title + '</a></div>';

                $('.content').append(html);
                i++;
            });

        });
};

Any input would be greatly appreciated!! Thanks

任何投入将不胜感激!!谢谢

3 个解决方案

#1


5  

I tried this in IE and it worked ok.

我在IE中尝试了这个,它运行正常。


$(document).ready(function() {
            $.get('http://dev.chriscurddesign.co.uk/burns/p/rc_rss.php?rcf_id=0',
                   'xml' , function(data) {
                alert(data);
            });
        });

This wont work in other browsers because of cross site scripting issues. The above code will only work if the page in which its residing is in the same domain. So, you have many options none of which is standard though. Best is make an ajax call to a url from your domain and then call the feed url from there ie; from server side. For more see this https://*.com/search?q=calling+webservice+from+another+domain+using+jquery

由于跨站点脚本问题,这在其他浏览器中不起作用。上述代码仅在其所在的页面位于同一域中时才有效。所以,你有很多选择,但没有一个是标准的。最好是从您的域中对URL进行ajax调用,然后从那里调用feed url;从服务器端。有关详情,请参阅此https://*.com/search?q=calling+webservice+from+another+domain+using+jquery

#2


1  

Thanks to pokrate for pointing out that it was a cross-domain issue. For future reference I'm using a php proxy now to grab the rss and then jquery to process it.

感谢pokrate指出这是一个跨域问题。为了将来参考,我现在使用php代理来获取rss然后jquery来处理它。

Here is the proxy (you need curl turned on in php):

这是代理(你需要在php中启用curl):

<?php
    $session = curl_init($_GET['url']);
    curl_setopt($session, CURLOPT_HEADER, false);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
    $xml = curl_exec($session);
    header("Content-Type: text/xml");appropriately
    echo $xml;
    curl_close($session);
?>

And here's my new javascript:

这是我的新javascript:

function get_rss_feed() {

    $(".content").empty();

    var feed = "http://dev.chriscurddesign.co.uk/burns/p/rc_rss.php?rcf_id=0";

    $.get("feedproxy.php?url=" + feed, function(d) {

        $(d).find('item').each(function() {

            var $item = $(this);
            var title = $item.find('title').text();
            var link = $item.find('link').text();

            var html = '<div class="entry"><a href="' + link + '" target="_blank">' + title + '</a></div>';

            $('.content').append(html);
        });

    });
};

Me = Happy Bunny :)

我=快乐兔子:)

#3


0  

Just use jFeed instead, this will make you code a lot simpler.

只需使用jFeed,这将使您的代码更简单。

#1


5  

I tried this in IE and it worked ok.

我在IE中尝试了这个,它运行正常。


$(document).ready(function() {
            $.get('http://dev.chriscurddesign.co.uk/burns/p/rc_rss.php?rcf_id=0',
                   'xml' , function(data) {
                alert(data);
            });
        });

This wont work in other browsers because of cross site scripting issues. The above code will only work if the page in which its residing is in the same domain. So, you have many options none of which is standard though. Best is make an ajax call to a url from your domain and then call the feed url from there ie; from server side. For more see this https://*.com/search?q=calling+webservice+from+another+domain+using+jquery

由于跨站点脚本问题,这在其他浏览器中不起作用。上述代码仅在其所在的页面位于同一域中时才有效。所以,你有很多选择,但没有一个是标准的。最好是从您的域中对URL进行ajax调用,然后从那里调用feed url;从服务器端。有关详情,请参阅此https://*.com/search?q=calling+webservice+from+another+domain+using+jquery

#2


1  

Thanks to pokrate for pointing out that it was a cross-domain issue. For future reference I'm using a php proxy now to grab the rss and then jquery to process it.

感谢pokrate指出这是一个跨域问题。为了将来参考,我现在使用php代理来获取rss然后jquery来处理它。

Here is the proxy (you need curl turned on in php):

这是代理(你需要在php中启用curl):

<?php
    $session = curl_init($_GET['url']);
    curl_setopt($session, CURLOPT_HEADER, false);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
    $xml = curl_exec($session);
    header("Content-Type: text/xml");appropriately
    echo $xml;
    curl_close($session);
?>

And here's my new javascript:

这是我的新javascript:

function get_rss_feed() {

    $(".content").empty();

    var feed = "http://dev.chriscurddesign.co.uk/burns/p/rc_rss.php?rcf_id=0";

    $.get("feedproxy.php?url=" + feed, function(d) {

        $(d).find('item').each(function() {

            var $item = $(this);
            var title = $item.find('title').text();
            var link = $item.find('link').text();

            var html = '<div class="entry"><a href="' + link + '" target="_blank">' + title + '</a></div>';

            $('.content').append(html);
        });

    });
};

Me = Happy Bunny :)

我=快乐兔子:)

#3


0  

Just use jFeed instead, this will make you code a lot simpler.

只需使用jFeed,这将使您的代码更简单。