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.
You can use the location. reload() method to reload or refresh an entire web page or just the content inside an element. The . reload() method can be triggered either explicitly (with a button click) or automatically.
Just run inspect div after the method is completed. To avoid this issue use the following code: $("#divid"). load(" #divid > *");
So the page needs to refresh after an ajax call….. In the controller action build the redirect url and include any route parameters that are needed. The Url is returned in the Json object to the calling javascript along with any other values e.g. the result of a database update.
You can use the location. reload() JavaScript method to reload the current URL. This method functions similarly to the browser's Refresh button. The reload() method is the main method responsible for page reloading.
By using jquery ajax you can reload your page
$.ajax({
type: "POST",
url: "packtypeAdd.php",
data: infoPO,
success: function() {
location.reload();
}
});
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");
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With