【问题标题】:json call does'nt update in IE 10json 调用不会在 IE 10 中更新
【发布时间】:2015-01-06 18:19:32
【问题描述】:

我使用这个小脚本来提供播放列表并每 20 秒更新一次。 - 出于某种原因,它在 ie10 中没有更新(我猜也是旧版本) - 我没看到哪里出了问题,有什么想法......?

    function playlist() {
    $.getJSON("/playlist/", function (data) {
        $("#play-now-arti").empty();
        $("#play-now-title").empty();
        $("#last-played").empty();
        var i = 0;
        $.each(data.PlayHistory.PlayInfo, function (index, value) {
            var arti = value["ARTI"];
            var title = value["TITLE"];
            i++;
            if (i == 1) {
                $("#now-playing-artist").html(arti);
                $("#now-playing-song").html(title);
            }
            else if (i > 1 && i < 8) {
                $("<li>" + arti + " - <span>" + title + "</span></li>").appendTo("#last-played");
            }
        });
    });
    setTimeout(playlist, 20000);
};
playlist();

【问题讨论】:

  • 也许和缓存有关?尝试每次发送一个唯一的 get 请求,也许将当前时间添加到 get url。
  • 我怀疑@zaf 可能是正确的。 IE 有时缓存东西很糟糕。您可以切换到底层的$.ajax 方法并将cache 参数指定为false,对于您的请求,当前默认为true,或者按照@zaf 的建议,自己附加一个时间戳。

标签: javascript jquery getjson


【解决方案1】:

确实是在缓存... - 通过添加“$.ajaxSetup({ cache: false });”到我的功能 IE 现在更新就像其他浏览器一样...

function playlist() {
            $.ajaxSetup({ cache: false });
            $.getJSON("/playlist/", function (data) {
                $("#playlist").empty();
                var i = 0;
                $.each(data.PlayHistory.PlayInfo, function (index, value) {
                    var arti = value["ARTI"];
                    var title = value["TITLE"];
                    var spotify = value["Spotify"];
                    i++;
                    if (i == 1) {
                        $("<li class=\"jp-playlist-current\"><div tabindex=\"0\" class=\"jp-playlist-item jp-playlist-current\"><span class=\"jp-artist\">" + arti + ":</span><a href=\"" + spotify + "\" target=\"_blank\" title=\"Lyt i Spotify\"><img src=\"/img/spotify.png\" style=\"border: 0;\" /></a><br><span class=\"jp-title\">" + title + "</span></div></li>").appendTo("#playlist");
                    }
                    else {
                        $("<li><div tabindex=\"0\" class=\"jp-playlist-item\"><span class=\"jp-artist\">" + arti + ":</span><a href=\"" + spotify + "\" target=\"_blank\" title=\"Lyt i Spotify\"><img src=\"/img/spotify.png\" style=\"border: 0;\" /></a><br><span class=\"jp-title\">" + title + "</span></div></li>").appendTo("#playlist");
                    }
                });
            });
            setTimeout(playlist, 200000);
        };
        playlist();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-29
    • 2017-02-13
    • 2014-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多