javascript 用javascript重新加载php页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19481115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
reload php page with javascript
提问by Alexandre Toqué
I have drawn a chess board in a php page. Every piece is set as draggable, and every tile as droppable. Once a piece is dropped on a tile, I'd like to reload the php page so the board can be drawn anew along with new positions. How can I do that: reloading the php page with javascript, without displaying a window asking for confirmation such as "To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier. ->Cancel; Resend" ?
我在一个 php 页面中画了一个棋盘。每个部分都设置为可拖动,每个图块都设置为可放置。一旦一块放在瓷砖上,我想重新加载 php 页面,以便可以重新绘制板和新位置。我该怎么做:使用 javascript 重新加载 php 页面,而不显示要求确认的窗口,例如“要显示此页面,Firefox 必须发送将重复之前执行的任何操作(例如搜索或订单确认)的信息” .->取消;重新发送”?
Or perhaps there are better solutions?
或者也许有更好的解决方案?
回答by
If you want to avoid having refresh reporting data (for any reason, including the user clicking the reload button) then use the POST-REDIRECT-GET pattern (http://en.wikipedia.org/wiki/Post/Redirect/Get). Read that, it will explain what to do.
如果您想避免刷新报告数据(出于任何原因,包括用户单击重新加载按钮),请使用 POST-REDIRECT-GET 模式(http://en.wikipedia.org/wiki/Post/Redirect/Get) . 阅读它,它将解释要做什么。
Quick solution: you could try:
快速解决方案:您可以尝试:
window.location.reload(true); //true sets request type to GET
Use GET, instead of POST and the dialog box you are getting will go away.
使用 GET,而不是 POST,您得到的对话框将消失。
Good luck!
祝你好运!
回答by Shankar Damodaran
Make use of
利用
window.location.reload();
回答by Sobin Augustine
will refresh automatically
会自动刷新
<script>
var timer = null;
function auto_reload()
{
window.location = 'http://domain.com/page.php'; //your page location
}
</script>
<!-- Reload page every 10 seconds. -->
<body onload="timer = setTimeout('auto_reload()',10000);">
reference http://davidwalsh.name/automatically-refresh-page-javascript-meta-tags
参考http://davidwalsh.name/automatically-refresh-page-javascript-meta-tags