【问题标题】:GET request using jQuery is not working in IE Explorer使用 jQuery 的 GET 请求在 IE Explorer 中不起作用
【发布时间】:2010-11-10 05:59:48
【问题描述】:

我有以下 jquery 代码:

function update() {
    $.get("getlatest.php", {
        id: $.cookie('last_post_id')
    }, function (response) {
        $('#board_posts').prepend(response);
        $('.incoming_post').slideDown("slow").effect("highlight", {}, 3000);
        $('.incoming_post').toggleClass("incoming_post").addClass("old_post");
    }, "html");
}

该功能将检查留言板是否有任何新帖子,如果有,将加载它们。 出于某种原因,新数据永远不会在 IE 7 中加载,但在 FF 和 Chrome 中加载良好。 此外,当我刷新页面时,数据也不会进来 - 只有在缓存被清除时。

对这个问题有帮助吗?

【问题讨论】:

    标签: php jquery ajax cross-browser


    【解决方案1】:

    Internet Explorer 缓存请求。请参阅cache flag for jQuery Ajax requests。它将向 URL 添加一个随机查询字符串参数(基于当前时间),以使其唯一且不可缓存。如果你愿意,你也可以自己做:'request.php?_=' + (+new Date())

    【讨论】:

    • +1。并不是每个人都真正意识到 IE 的这种奇怪行为并最终将责任归咎于自己的代码库。但是Firefox按预期工作。好消息是,在使用 Ajax 时总是发送一个随机参数。故意缓存是个例外。
    【解决方案2】:

    使用jQuery.ajaxSetup 方法将cache 选项设置为false。或者使用 $.ajax 方法来做同样的事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-18
      • 1970-01-01
      • 2014-02-09
      相关资源
      最近更新 更多