1

In our login/logout javascript, which works in a modal box, I'd like to reload the current page after a user logs in our out, but only if the current page was not loaded as a POST--I don't want to try to double post data to the server.

Is there any way to tell whether window.location.reload() will be sent as a GET or a POST, so that I can redirect POSTs to our front page instead?

Karptonite
  • 1,490
  • 2
  • 14
  • 30

1 Answers1

1

JavaScript doesn't have access to the request method [1], but you could check with PHP if there is any POST data, and set a JS variable:

<script type="javascript">
    var post = <?php if(isset($_POST)) echo 'true'; else echo 'false'; ?>;
</script>

Although this is not reliable (users could manually change it) so you shouldn't rely on this to avoid duplicate data...

Community
  • 1
  • 1
aurbano
  • 3,324
  • 1
  • 25
  • 39
  • Thanks. I guess I'll use window.location =window.location.href to avoid reposting, and maybe filter out some of the more obvious post links. – Karptonite Apr 03 '12 at 17:33