【问题标题】:Internet Explorer won't update AJAX handled content on refresh?Internet Explorer 不会在刷新时更新 AJAX 处理的内容?
【发布时间】:2012-01-27 01:03:54
【问题描述】:

我有一个通过 Jquery AJAX 调用从 XML 文件中获取内容的页面。

问题是它会在刷新时为除 IE 之外的每个浏览器更新 XML 文件中的内容。

我试图用元标记解决这个问题

<meta http-equiv="expires" content="-1"/>
<meta http-equiv="cache-control" content="no-cache,must-revalidate" />
<meta http-equiv="pragma" content="no-cache"/>

这是相关javascript的一小部分

$(document).ready(function(){ 
$.ajax({type: "GET",url: "file1.xml",dataType: "xml", success: parseXml });
}

function parseXml(xml){
document.getElementById(eventMonthName).innerHTML=firstxmlvari.getElementsByTagName('month')[0].childNodes[0].nodeValue;
}

任何建议将不胜感激!

【问题讨论】:

  • 我不知道您使用什么后端技术,但您应该尝试设置 HTTP 标头。以我的经验,较旧的 IE 对元标记的反应不佳。以下是如何在 php.ini 中操作 http 标头。 jonasjohn.de/snippets/php/headers.htm

标签: jquery internet-explorer-8 refresh


【解决方案1】:

由于 jQuery 的 .load 方法不提供关闭缓存的便捷方式,我在请求中添加了一个时间戳参数,它只是在控制器级别被忽略:

$('#userDialog').load('/Users/Edit/' + someValue + '?timestamp=' + new Date().getTime(), function () {
...
});

或:

$('#userDialog').load('/Users/Create', { timestamp: new Date().getTime() }, function () {
...
});

这确实只有 IE 需要,并且从版本 10 开始。

【讨论】:

    【解决方案2】:

    您还可以使用“cache: false”选项,该选项的工作方式与 Akos Lukacs 提到的相同。结果是一样的,但您不必创建自己的日期。

    $(document).ready(function() {
        $.ajax({
            type: "GET",
            url: "/echo/xml/",
            cache: false,
            dataType: "xml",
            success: parseXml
        });
    });
    

    【讨论】:

      【解决方案3】:

      谢谢,我遇到了类似的问题(当然只在 IE 中),下拉列表在请求后没有刷新。添加时间戳可以结合使用;

      $(document).trigger("ready");

      在成功功能中,干杯!

      【讨论】:

        【解决方案4】:

        是的,可能您遇到了 IE 的激进缓存... 尝试设置 HTTP 标头,但对我有用的是将当前时间附加到查询字符串,如下所示:

        $(document).ready(function() {
            $.ajax({
                type: "GET",
                url: "/echo/xml/",
                data: {
                    _rnd: new Date().getTime()
                },
                dataType: "xml",
                success: parseXml
            });
        });
        
        function parseXml(xml) {
            alert(xml);
        }
        

        JSFIDDLE 上的示例:http://jsfiddle.net/WVBDc/,检查传出的 HTTP 请求。

        【讨论】:

        • 哇!谢谢,这正是我想要的!
        猜你喜欢
        • 1970-01-01
        • 2019-07-06
        • 1970-01-01
        • 2011-10-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多