在 JS 中使用 history.pushState 加载页面时后退按钮不起作用

时间:2021-01-28 09:33:31

标签: javascript ajax windows pushstate popstate

我正在尝试使用 history.pushState 通过 ajax 加载页面并成功加载页面,但在这种情况下后退按钮不起作用。请在下面检查我的代码:

function processAjaxData(response, urlPath){
    document.write(response)
    document.title = '';
    window.history.pushState({"html":response,"pageTitle":''},"", urlPath);
}

$('#apply_loader').click(function(e){
   
      var nextPage = $(this).attr('href');
      $.get(nextPage,  // url
      function (data, textStatus, jqXHR) {  // success callback
        processAjaxData(data,nextPage);
      }
    );
});

我正在尝试使用下面的 popstate 来识别后退按钮点击。

  $(window).on('popstate', function(event) {
    console.log('asd');
     location.reload();
  });

0 个答案:

没有答案