我想创建一个按钮来重新加载页面而不丢失$_POST
数据和$_SESSION
.
在网上,我找到了这段代码:
onclick="document.location.reload();"
这是我的按钮的代码:
<a class="button" href="" style="font-size: 0.7em; padding: 5px 10px;" onclick="document.location.reload();">Recharger la page</a>
但当我点击按钮时,我就输了$_POST
数据和$_SESSION
.
如果我尝试使用键盘命令Ctrl+R(铬)或F5(Firefox、IE9),浏览器显示一条警报,通知我再次尝试提交表单。如果我接受,它就会起作用。
如何使用 JavaScript 命令重现这种浏览器刷新?还是我的按钮代码错误?
非常感谢您的帮助。
尝试使用
location.reload(true);
这将执行“硬”刷新,不仅重建 DOM,而且还从服务器重新检索任何资源。
您可以在 Mozilla 开发者 wiki 中阅读更多内容。 https://developer.mozilla.org/en/DOM/window.location#section_6
显然,location.reload()
相当于F5
在脚本编写中,同时Ctrl+F5
/ Ctrl+R
可以使用模拟location.reload(true)
.
Also, as ThiefMaster mentioned, you're missing ;return false
at the end of your onclick
statement, or you should set the href
to javascript:void 0
* to prevent the browser from following the link.
*Or any other piece of JavaScript that returns undefined
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)