javascript - Use jQuery to read a JSON Google news feed - Stack Overflow

I'm using this jQuery plugin (fiddle) to read Google news rss feed. It requires converting the fee

I'm using this jQuery plugin (fiddle) to read Google news rss feed. It requires converting the feed to json format. Then I came across this thread that shows a Google feed in JSON format without the help of Yahoo Pipe:

.0&q=http%3A%2F%2Fnews.google%2Fnews%3Foutput%3Drss%26num%3D8

I tried the plugin's method to parse the JSON Google feed but failed. Can anyone show me the correct way to read that feed?

My attempt:

<script>
$('#rssdata').ready(function()
{
    var pipe_url = '.0&num=8&q=http%3A%2F%2Fnews.google%2Fnews%3Foutput%3Drss';
    $.getJSON(pipe_url,function(data)
    {
        $(data.feed.entries).each(function(index,entry)
        {

            var item_html = '<li><a target="_blank" href="'+entry.link+'">'+entry.title+'</a></li>';
            $('#rssdata ul.rss-items').append(item_html);
        });
        $('#rssdata div.loading').fadeOut();
        $('#rssdata ul.rss-items').slideDown();
    });
});
</script>

Google News Feed:

{"responseData": {"feed":{"feedUrl":"\u003drss\u0026num\u003d8","title":"Top Stories - Google News","link":"\u003d1\u0026amp;ned\u003dus\u0026amp;hl\u003den\u0026amp;num\u003d8","author":"","description":"Google News","type":"rss20","entries":[{"title":"Malaysia Airlines loses contact with plane en route to Beijing with 239 aboard - CBS News","link":"http://....

I'm using this jQuery plugin (fiddle) to read Google news rss feed. It requires converting the feed to json format. Then I came across this thread that shows a Google feed in JSON format without the help of Yahoo Pipe:

http://ajax.googleapis./ajax/services/feed/load?v=1.0&q=http%3A%2F%2Fnews.google.%2Fnews%3Foutput%3Drss%26num%3D8

I tried the plugin's method to parse the JSON Google feed but failed. Can anyone show me the correct way to read that feed?

My attempt:

<script>
$('#rssdata').ready(function()
{
    var pipe_url = 'http://ajax.googleapis./ajax/services/feed/load?v=1.0&num=8&q=http%3A%2F%2Fnews.google.%2Fnews%3Foutput%3Drss';
    $.getJSON(pipe_url,function(data)
    {
        $(data.feed.entries).each(function(index,entry)
        {

            var item_html = '<li><a target="_blank" href="'+entry.link+'">'+entry.title+'</a></li>';
            $('#rssdata ul.rss-items').append(item_html);
        });
        $('#rssdata div.loading').fadeOut();
        $('#rssdata ul.rss-items').slideDown();
    });
});
</script>

Google News Feed:

{"responseData": {"feed":{"feedUrl":"http://news.google./news?output\u003drss\u0026num\u003d8","title":"Top Stories - Google News","link":"http://news.google./news?pz\u003d1\u0026amp;ned\u003dus\u0026amp;hl\u003den\u0026amp;num\u003d8","author":"","description":"Google News","type":"rss20","entries":[{"title":"Malaysia Airlines loses contact with plane en route to Beijing with 239 aboard - CBS News","link":"http://....
Share Improve this question edited May 23, 2017 at 12:15 CommunityBot 11 silver badge asked Mar 8, 2014 at 19:21 RedGiantRedGiant 4,76911 gold badges63 silver badges151 bronze badges 1
  • This is great. I want to get the news feed from google which is related to one pany lets say as Microsoft. How to get only news feed related to only Microsoft? – Mihir Commented Oct 16, 2014 at 9:39
Add a ment  | 

1 Answer 1

Reset to default 3

Your code is not working because of the Same-origin policy.

One possible solution is to use JSONP which is supported by Google News Feed API.

So you can do:

$('#rssdata').ready(function () {
    $.ajax({
        url: 'http://ajax.googleapis./ajax/services/feed/load?v=1.0&num=8&q=http%3A%2F%2Fnews.google.%2Fnews%3Foutput%3Drss',
        dataType: 'jsonp',
        success: function (data) {
            //console.log(data.feed.entries);
            $(data.responseData.feed.entries).each(function (index, entry) {
                var item_html = '<li><a target="_blank" href="' + entry.link + '">' + entry.title + '</a></li>';
                $('#rssdata ul.rss-items').append(item_html);
            });
            $('#rssdata div.loading').fadeOut();
            $('#rssdata ul.rss-items').slideDown();
        },
        error: function () {}

    });
});

Updated Fiddle

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745657502a4638630.html

相关推荐

  • javascript - Use jQuery to read a JSON Google news feed - Stack Overflow

    I'm using this jQuery plugin (fiddle) to read Google news rss feed. It requires converting the fee

    4小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信