Reload browser window after POST without prompting user to resend POST data

后端 未结 14 2023
盖世英雄少女心
盖世英雄少女心 2020-11-29 05:47

When a user visits my website there is a \"Login\" link on every page. Clicking this uses some JavaScript to show an overlay window where the user is prompted for their cred

相关标签:
14条回答
  • 2020-11-29 06:12

    This can be solved also with POST/REDIRECT/GET pattern.
    Which is more elegant:
    How do I reload a page without a POSTDATA warning in Javascript?

    0 讨论(0)
  • 2020-11-29 06:13

    This worked for me.

    window.location = window.location.pathname;

    Tested on

    • Chrome 44.0.2403
    • IE edge
    • Firefox 39.0
    0 讨论(0)
  • 2020-11-29 06:13

    When we want to refresh the parent page from the child page without any prompt.

    Here is the code:

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

    This simply refreshes the parent page without any prompt.

    0 讨论(0)
  • 2020-11-29 06:16

    This is an older post, but I do have a better solution. Create a form containing all of your post values as hidden fields and give the form a name such as:

    <form name="RefreshForm" method="post" action="http://yoursite/yourscript">
        <input type="hidden" name="postVariable" value="PostData">
    </form>
    

    Then all you need to do in your setTimeout is RefreshForm.submit();

    Cheers!

    0 讨论(0)
  • 2020-11-29 06:16

    To reload opener window with all parameters (not all be sent with window.location.href method and method with form.submit() is maybe one step to late) i prefer to use window.history method.

    window.opener.history.go(0);
    
    0 讨论(0)
  • 2020-11-29 06:20

    What you probably need to do is redirect the user after the POST / Form Handler script has been ran.

    In PHP this is done like so...

    <?php
    // ... Handle $_POST data, maybe insert it into a database.
    // Ok, $_POST data has been handled, redirect the user
    header('Location:success.php');
    die();
    ?>
    

    ... this should allow you to refresh the page without getting that "Send Data Again" warning.

    You can even redirect to the same page (if that's what you're posting to) as the POST variables will not be sent in the headers (and thus not be there to re-POST on refresh)

    0 讨论(0)
提交回复
热议问题