php reload page without posting data

前端 未结 6 1819
悲&欢浪女
悲&欢浪女 2020-12-11 04:35

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

I\'ve tried

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

相关标签:
6条回答
  • 2020-12-11 04:57

    Got this to work...

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

    0 讨论(0)
  • 2020-12-11 05:09

    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.

    0 讨论(0)
  • 2020-12-11 05:10

    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.

    0 讨论(0)
  • 2020-12-11 05:10

    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.

    0 讨论(0)
  • 2020-12-11 05:17

    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!

    0 讨论(0)
  • 2020-12-11 05:18

    You could try:

    window.location.reload(true); //true sets request type to GET
    
    0 讨论(0)
提交回复
热议问题