首页 > 解决方案 > 在没有页面加载的情况下在 jQuery 中加载页面

问题描述

正如我们所知,react 不会在单击锚点时加载窗口。这就是为什么响应网络应用程序很快。我想要 jQuery 中的相同功能。我想在 Jquery 中加载页面而不加载页眉、页眉和页脚。我该怎么做?我什至不知道我能不能做到。

  $(document).on("click", function (e) {
    let anchor = $(e.target);
    var url = anchor.attr("data-url-redirect");
    if (e.target.nodeName == "A") {
      // console.log(anchor, url);

      $.ajax({
        url: url + '.html',
        success: function (result) {
          $(".pageWrapper").html(result);
          console.log(result, url);

          if (history.pushState) {
            var newurl =
              window.location.protocol +
              `//` +
              window.location.host +
              window.location.pathname +
              "/" +
              url;
            window.history.pushState({ path: newurl }, "", newurl);
          }
        },
      });
    }
  });
});

这是我写的代码。我可以加载页面并更改 URL。但是当我刷新分页符时。请让我知道是否可以使用 jQuery。如果有可能,那么我该如何实现呢?

标签: htmljqueryajax

解决方案


推荐阅读