【问题标题】:Ajax will not load and show data on IE 11 cause cacheAjax 不会在 IE 11 上加载和显示数据导致缓存
【发布时间】:2019-05-16 11:07:23
【问题描述】:

我使用 Ajax 来检查数据并将其显示在页面上,并且我使用清漆缓存。 数据显示在所有浏览器上,IE 11 除外,直到我停用清漆缓存。

function checkMyData() {
var surl = 'index.php?eID=thismydata';
if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0) {
    surl += '&hash=' + Math.random();
}
$.ajax({
    type: "GET",
    url: siteurl + surl,
    asynchronous: true,
    data: 'mode=datalist' +
            '&initdatalist=' + initdatalist +
            '&datastr=' + datastr,      
    success: function (answer) {
        var response;
        try {
            response = eval('(' + answer + ')');
        } catch (err) {
            alert('Err: ' + answer);
            return;
        }
        if (initdatalist == 1)
            initdatalist = 0;
        $basic_cont = '<div class="row"><div class="col-md-6 col-md-offset-3"><p class="data-title">' + 
                response.firstmatch + response.otherdata + '</p></div></div>' +
                response.matches;

        $("#thisdaydata").empty();
        $($basic_cont).appendTo("#thisdaydata");
    }
});
}

所有浏览器的 HTML 输出(IE 11 除外):

<div id="thisdaydata">
<div class="row">
   <div class="col-md-6 col-md-offset-3">
       <p class="data-title">data here</span></p>
   </div>
</div>

IE 11 的 HTML 输出:

<div id="thisdaydata"></div>

这个 ajax 是否与 IE 11 不兼容?

【问题讨论】:

    标签: javascript ajax debugging internet-explorer varnish


    【解决方案1】:

    IE 会自动缓存来自 GET 请求的响应,而其他浏览器会让您决定是否要缓存结果。一旦 IE 成功发出 GET 请求,它甚至不会再进行 AJAX 调用,直到该对象上的缓存过期。您可以在 ajax 中添加 cache : false 值。更多细节和方法可以参考this articlethis question

    【讨论】:

    • 谢谢,但是cache : false 没有解决问题
    • 我在我这边重现了你的代码,我认为 ajax 可以在 IE11 中运行良好。 IE11的F12开发者工具中是否有报错信息?
    猜你喜欢
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    • 2011-02-27
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多