【问题标题】:History.js - sometimes only shows ajax content when clicking back buttonHistory.js - 有时仅在单击后退按钮时显示 ajax 内容
【发布时间】:2013-11-04 09:51:59
【问题描述】:

我使用 History.js,有时当我单击返回按钮时,我只从 ajax 调用而不是整个页面(包括 ajax 调用)中获取内容。这会导致网站看起来很糟糕,因为没有加载任何脚本、css 或 html“容器”。

  1. 我浏览我的页面。
  2. 我在地址栏中键入另一个网站。
  3. 我点击后退按钮 - 现在只显示上一个 ajax 调用的 html,没有 css、js 或其他 html

为什么会发生这种情况,我该如何解决?

我的代码如下所示:

History.Adapter.bind(window, 'statechange', function(){
    var State = History.getState();
    $.ajax({
        url: State.url,
        type: 'get',
        beforeSend: function(xhr){ 
            xhr.setRequestHeader('X-PJAX', true); 
        },
        success: function(resp, status, xhr) { 
            $('#wrapper').html(resp); 
        }
    });
});

【问题讨论】:

    标签: javascript history.js


    【解决方案1】:

    我通过在我的 ajax 响应中禁用缓存来修复它。

    Cache-Control: no-cache, no-store, must-revalidate

    现在,当我单击后退按钮时,整个页面都会被加载,而不仅仅是 ajax 响应。

    【讨论】:

      猜你喜欢
      • 2011-12-18
      • 1970-01-01
      • 2012-05-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多