【问题标题】:jQuery with YQL RSS Feeds randomly returning null带有 YQL RSS 提要的 jQuery 随机返回 null
【发布时间】:2016-07-22 03:10:43
【问题描述】:

我正在使用FeedEk jQuery 插件,它使用 YQL API,尝试显示三个 RSS 提要。

大多数情况下一切正常,但每隔一段时间我会从三个提要中的一个提要中收到results: null,但通常是第二个和第三个要被调用,很少是第一个。我已经检查了提要本身,它们没有显示任何问题,我还在雅虎控制台上对其进行了测试,但没有显示任何问题。 这不是呼叫限制问题,因为我在测试时每天从我的 IP 中几乎没有达到 300 个呼叫。

我启用了诊断,我看到的唯一与result: null 提要不同的是它在info 部分Using encoding from response content-type header (UTF-8) as XML document does not specify encoding. 中有以下消息

这是我正在打的电话

SELECT channel.item FROM feednormalizer WHERE output="rss_2.0" AND url ="http://feeds.arstechnica.com/arstechnica/index" LIMIT 8

这是插件代码

/*
* FeedEk jQuery RSS/ATOM Feed Plugin v3.0 with YQL API (Engin KIZIL http://www.enginkizil.com)
* http://jquery-plugins.net/FeedEk/FeedEk.html  https://github.com/enginkizil/FeedEk
* Author : Engin KIZIL http://www.enginkizil.com
*/

(function ($) {
    $.fn.FeedEk = function (opt) {
        var def = $.extend({
            MaxCount: 5,
            ShowDesc: true,
            ShowPubDate: true,
            DescCharacterLimit: 0,
            TitleLinkTarget: "_blank",
            DateFormat: "",
            DateFormatLang:"en"
        }, opt);

        var id = $(this).attr("id"), i, s = "", dt;
        $("#" + id).empty();
        if (def.FeedUrl == undefined) return;
        $("#" + id).append('<div style="width:100%;text-align:center;color:#424242;"><div class="loader"></div></div>');

        var YQLstr = 'SELECT channel.item FROM feednormalizer WHERE output="rss_2.0" AND url ="' + def.FeedUrl + '" LIMIT ' + def.MaxCount;

        $.ajax({
            url: "https://query.yahooapis.com/v1/public/yql?q=" + encodeURIComponent(YQLstr) + "&format=json&diagnostics=true&callback=?",
            dataType: "json",
            success: function (data) {
                $("#" + id).empty();
                if (!(data.query.results.rss instanceof Array)) {
                    data.query.results.rss = [data.query.results.rss];
                }
                $.each(data.query.results.rss, function (e, itm) {
                    s += '<li><div class="itemTitle">' + itm.channel.item.title + '</div>';

                    if (def.ShowPubDate){
                        dt = new Date(itm.channel.item.pubDate);
                        s += '<div class="itemDate">';
                        if ($.trim(def.DateFormat).length > 0) {
                            try {
                                moment.lang(def.DateFormatLang);
                                s += moment(dt).format(def.DateFormat);
                            }
                            catch (e){s += dt.toLocaleDateString();}
                        }
                        else {
                            s += dt.toLocaleDateString();
                        }
                        s += '</div>';
                    }
                    if (def.ShowDesc) {
                        s += '<div class="itemContent">';
                         if (def.DescCharacterLimit > 0 && itm.channel.item.description.length > def.DescCharacterLimit) {
                            s += itm.channel.item.description.substring(0, def.DescCharacterLimit) + '...';
                        }
                        else {
                            s += itm.channel.item.description;
                         }
                         s += '</div>';
                    }
                });
                $("#" + id).append('<ul class="feedEkList">' + s + '</ul>');
            }
        });
    };
})(jQuery);

最后是从 YQL 返回的失败结果的 XML

/**/
jQuery112204319277675822377_1459586267516({
    "query": {
        "count": 0,
        "created": "2016-04-02T08:37:48Z",
        "lang": "en-US",
        "diagnostics": {
            "publiclyCallable": "true",
            "url": {
                "execution-start-time": "1",
                "execution-stop-time": "59",
                "execution-time": "58",
                "content": "http://feeds.arstechnica.com/arstechnica/index"
            },
            "info": "Using encoding from response content-type header (UTF-8) as XML document does not specify encoding.",
            "user-time": "60",
            "service-time": "58",
            "build-version": "0.2.430"
        },
        "meta": {
            "url": {
                "id": "http://feeds.arstechnica.com/arstechnica/index",
                "status": "200",
                "headers": {
                    "header": [{
                        "name": "Content-Type",
                        "value": "text/xml; charset=UTF-8"
                    }, {
                        "name": "ETag",
                        "value": "m+oG6+UhrscSbLRLhGlL3lvlwNo"
                    }, {
                        "name": "Last-Modified",
                        "value": "Sat, 02 Apr 2016 07:32:51 GMT"
                    }, {
                        "name": "Content-Encoding",
                        "value": "gzip"
                    }, {
                        "name": "Expires",
                        "value": "Sat, 02 Apr 2016 07:40:36 GMT"
                    }, {
                        "name": "Cache-Control",
                        "value": "private, max-age=0"
                    }, {
                        "name": "X-Content-Type-Options",
                        "value": "nosniff"
                    }, {
                        "name": "X-XSS-Protection",
                        "value": "1; mode=block"
                    }, {
                        "name": "Server",
                        "value": "ATS"
                    }, {
                        "name": "Date",
                        "value": "Sat, 02 Apr 2016 08:37:48 GMT"
                    }, {
                        "name": "Age",
                        "value": "0"
                    }, {
                        "name": "Connection",
                        "value": "close"
                    }, {
                        "name": "Via",
                        "value": "http/1.1 ec2.ycs.bf1.yahoo.net (ApacheTrafficServer [cSsNfU])"
                    }
                    ]
                }
            }
        },
        "results": null
    }
});

【问题讨论】:

    标签: jquery ajax xml rss yql


    【解决方案1】:

    在做了更多实验后,我唯一能想到的解决方案是 YQL 不喜欢需要更长时间才能提供服务的提要。较慢和高需求的饲料似乎会出现这个问题。

    我有一种感觉,这可能是因为 API 代码有一个超时,控制台的电源代码没有并且愉快地等待,因此它与一个而不是另一个一起工作。

    不幸的是,唯一的解决方案似乎是小心使用您使用的提要。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多