Alex Rivera | Logout

AJAX reload page with POST

Asked 2011-11-25T11:16:19.827
19

Can anybody tell me how to refresh the current page with JavaScript, having a POST variable modified or added?

To be clear, I want to set some POST variables prior to reloading the page.

Edit
Report

1 Answer

7

If you want to refresh the entire page, it makes no sense to use AJAX. Use normal Javascript to post the form element in that page. Make sure the form submits to the same page, or that the form submits to a page which then redirects back to that page

Javascript to be used (always in myForm.php):

function submitform()
{
  document.getElementById('myForm').submit();
}

Suppose your form is on myForm.php: Method 1:

<form action="./myForm.php" method="post" id="myForm">
    ...
</form>

Method 2:

myForm.php:

<form action="./myFormActor.php" method="post" id="myForm">
    ...
</form>

myFormActor.php:

<?php
    //all code here, no output
    header("Location: ./myForm.php");
?>
answered 2011-11-25T11:35:34.583

Your Answer