如何在没有页面重新加载的情况下在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(),
参数。
This works, but i want the url to change because I have many parameters there and of course with the data: "urut="+$(".urut").val(),
parameter as well.
答
现在,您可以在大多数现代浏览器中执行此操作!
你可以为你的成功行动做到这一点:
you can do this to your success action :
window.history.pushState("object or string", "Title", "/new-url");
查看此帖子至修改URL而不重新加载页面以获取基本操作方法。
See this this post to Modify the URL without reloading the page for a basic how-to.
附加说明:
Additional Note:
- 第一个参数是我们需要的数据,如果状态是web
页面更改,例如,每当有人按下后面或浏览器中的
转发按钮时。请注意,在Firefox中,这个数据是
,限制为640k个字符。 - title是第二个参数,可以是一个字符串,但是当时
的写作,每个浏览器只是忽略它。 - 这个最后一个参数是我们想要出现在地址
bar中的URL。