Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX reload page with POST

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.

like image 610
artaxerxe Avatar asked Nov 25 '11 11:11

artaxerxe


People also ask

How do you reload the same page after AJAX success?

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.

How do I load a div after AJAX success?

Just run inspect div after the method is completed. To avoid this issue use the following code: $("#divid"). load(" #divid > *");

How reload page after AJAX call in MVC?

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.

How do you refresh a page using JavaScript?

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.


2 Answers

By using jquery ajax you can reload your page

$.ajax({
    type: "POST",
    url: "packtypeAdd.php",
    data: infoPO,
    success: function() {   
        location.reload();  
    }
});
like image 88
mapet Avatar answered Oct 04 '22 22:10

mapet


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");
?>
like image 20
Pranav Hosangadi Avatar answered Oct 04 '22 22:10

Pranav Hosangadi