json调用在IE 10中进行了更新

时间:2015-01-05 09:42:12

标签: javascript jquery getjson

我使用这个小脚本来提供播放列表并每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();

1 个答案:

答案 0 :(得分:0)

这是缓存,确实...... - 添加“$ .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();