I'm creating an application in PHP which programmatically sends a POST request from within the home.php file as follows:
$.ajax({
type: "POST",
url: home.php,
data: {id: 5 },
success: function(data) {
alert(data);
}
});
The alert function shows the expected output:
array(1){
["id"] => string(1) "5"
}
...
but when I include
<?php
var_dump($_POST);
?>
I get unsatisfactory results, which suggest that none of the data I'm sending from the client-side to the server side is persisting:
array(0) { }
I have also tried establishing sessions and updating session variables through the posted data, but in this case the modified session variable does not get echoed to the client after the POST request.
<?php
session_start();
$_SESSION["varname"] = "green";
echo $_SESSION["varname"];
?>
echoes "green", as expected.
<?php
$_SESSION["varname"] = $_POST["id"];
echo $_SESSION["varname"];
?>
echoes nothing.