Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery location.reload()不带参数_Jquery - Fatal编程技术网

Jquery location.reload()不带参数

Jquery location.reload()不带参数,jquery,Jquery,我有下面的代码 <button id="RefreshMe">Refresh Page</button> <script> jQuery('#PageRefresh').click(function() { location.reload(); }); </script> 刷新页面 jQuery(“#页面刷新”)。单击(函数(){ location.reload(); }); 这很好,但是我的页面在表单中有一些隐藏值,因此它没有重新加载

我有下面的代码

<button id="RefreshMe">Refresh Page</button>
<script>
jQuery('#PageRefresh').click(function() {
    location.reload();
});
</script>
刷新页面
jQuery(“#页面刷新”)。单击(函数(){
location.reload();
});

这很好,但是我的页面在表单中有一些隐藏值,因此它没有重新加载www.example.com,而是重新加载www.example.com?a=111等,这会导致错误,因为uri太大。我希望用户返回www.example.com而不是www.example.com?a=111还需要添加什么?

更好的答案是:

document.location = document.location.replace(/[\?].*/,'');
  history.pushState({}, 'title', '/');
这将刷新没有参数和路径的页面(基本上是您的主页)。但假设您有一个非主页,例如:

yoursite.com/pricing?myparam=shazam
如果只想删除参数,可以执行以下操作:

history.pushState({}, 'title', '/pricing');
你最终会得到这样的结果:

yoursite.com/pricing