php reload page without posting data

2019-01-19 19:52发布

I'm trying to refresh a page without sending POST from the previous time.

I've tried

window.open("postme.php?r=t", "_self");

Which appends a ?r=t to the end but it doesn't appear to refresh the page as the page displays a number of files in a directory which hasn't change even though I have moved or deleted them.

Can you specify the URL in window.location.reload();?

Any ideas?

Thanks

6条回答
Emotional °昔
2楼-- · 2019-01-19 20:05

Well.. late too I suppose, but then it could help someone. I used :

window.location.href = window.location.href;

In replacement of location.reload(); this will refresh the page without prompting user to resend information.

查看更多
劫难
3楼-- · 2019-01-19 20:08

Got this to work...

window.location = "postme.php?r=t";

查看更多
Animai°情兽
4楼-- · 2019-01-19 20:16

i know this is way late, and hope it applies: i had the same problem where when someone is confirming their inventory selection, it then emails the order [or subtracts from inventory database] then displays their order. then if they refresh, it resubmits the data. so i added a session_destroy(). but then when they refresh, there're lots of errors.

SO - i divided the code into [a]email the order/subtract from the inventory database, then [b]used a javascript "document.location.href='nextPage.php'" because i sometimes have problems using PHP's "location(nextpage.php)". anyway, it emails the info, then goes to the page that displays it. then one can refresh all they want and all that happens is it displays over and over.

hope that helps!

查看更多
forever°为你锁心
5楼-- · 2019-01-19 20:20

Redirect the user to the same page after you're finished using their POST data.

$URI = $_SERVER['REQUEST_URI'];

if(!empty($_POST)){
    //magic

    header("location:$URI");
}

Now when you refresh, it won't have POST data to resubmit.

查看更多
我想做一个坏孩纸
6楼-- · 2019-01-19 20:21

You could try:

window.location.reload(true); //true sets request type to GET
查看更多
趁早两清
7楼-- · 2019-01-19 20:23

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.

查看更多
登录 后发表回答