微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 如何在没有页面重新加载的情况下在ajax中成功更改URL

这是ajax

$(".urut").change(function() {
  $.ajax({
    url: "<?PHP echo base_url(); ?>categories/brand/<?= $link_brand; ?>?l=<?= $l; ?>&h=<?= $h; ?>&city=<?= $city; ?>&city_name=<?= $city_name; ?>&ket=view",
    type: "POST",
    data: "urut=" + $(".urut").val(),
    success: function(data) {
      $("#result").html(data);
    }
  })
})

这是有效的,但我想要更改网址,因为我有多参数,当然还有数据:“urut =”$(“.urut”).val(),参数也是如此.

解决方法:

您现在可以在大多数“现代”浏览器中执行此操作!

你可以为你的成功行动做到这一点:

window.history.pushState("object or string", "Title", "/new-url");

有关基本操作方法,请参阅此帖子至Modify the URL without reloading the page.

Additional Note:

  1. The first parameter is the data we’ll need if the state of the web
    page changes, for instance whenever someone presses the back or
    forwards button in their browser. Note that in Firefox this data is
    limited to 640k characters.
  2. title is the second parameter which can be a string, but at the time
    of writing, every browser simply ignores it.
  3. This final parameter is the URL we want to appear in the address
    bar.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐