Unexpected Caching of AJAX results in IE8

前端 未结 10 2174
走了就别回头了
走了就别回头了 2020-11-28 01:59

I\'m having a serious issue with Internet Explorer caching results from a JQuery Ajax request.

I have header on my web page that gets updated every time a user navig

10条回答
  •  难免孤独
    2020-11-28 02:28

    As marr75 mentioned, GET's are cached.

    There are a couple of ways to combat this. Aside from modifying the response header, you can also append a randomly generated query string variable to the end of the targeted URL. This way, IE will think it is a different URL each time it is requested.

    There are multiple ways to do this (such as using Math.random(), a variation on the date, etc).

    Here's one way you can do it:

    var oDate = new Date();
    var sURL = "/game/getpuzzleinfo?randomSeed=" + oDate.getMilliseconds();
    $.get(sURL, null, function(data, status) {
        // your work
    });
    

提交回复
热议问题