I need to pass a jquery variable from one PHP file to another.
for this, I am posting the variable into the server using ajax in page1.php and getting the variable from the server using PHP in page2.php
In page1.php,
$.ajax({
url: "page2.php",
type: "POST",
data:{"myDat":activeCount}
}).done(function(data) {
console.log(data);
});
In page2.php,
<?php
$data1 = isset($_REQUEST['myDat'])?$_REQUEST['myDat']:"";
echo $data1;
?>
I am getting the ajax code (console.log(data)) get printed on the console.
But I am not getting the data in PHP (echo $data1)
Can anyone please help?
$_POST, not$_REQUEST. andvar_dump($_POST); exiton your PHP script so you can check data is being received okconsole.log(data)shows the page2 response, theecho $data1clearly must have gotten through. Try to debug a bit further / and reexplain what issue you see.