最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Problems reading RSS feed with jQuery.get() - Stack Overflow

programmeradmin6浏览0评论

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?

Here's my feed: .php?rcf_id=0

Here's my code:

function get_rss_feed() {

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

        $.get(".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

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?

Here's my feed: 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

Share Improve this question asked Mar 22, 2010 at 10:35 bbeckfordbbeckford 4,4776 gold badges37 silver badges48 bronze badges 2
  • Does your XML validate? E.g.: validome/xml/validate – Álvaro González Commented Mar 22, 2010 at 11:08
  • Please disregard my ment. It does validate. – Álvaro González Commented Mar 22, 2010 at 11:16
Add a ment  | 

3 Answers 3

Reset to default 5

I tried this in IE and it worked ok.


$(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://stackoverflow./search?q=calling+webservice+from+another+domain+using+jquery

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.

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

<?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:

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

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

发布评论

评论列表(0)

  1. 暂无评论