Search code examples
javascriptjquerygetjson

json call does'nt update in IE 10


I use this tiny script to feed a playlist and updates it every 20 sec. - for some reason it does'nt update in ie10 (and older versions too, I guess) - I failed to see where it goes wrong, any ideas...?

    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();

Solution

  • It was caching, indeed... - by adding "$.ajaxSetup({ cache: false });" to my function IE now updates just like the other browsers...

    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();