I have the following jquery:
$.ajax({
type: "POST",
url: "getchoices.php",
dataType: 'json',
data: JSON.stringify({ "userName": "test1", "password" : "test2" })
});
With corresponding PHP:
<?php
$json = $_POST;
print_r($json);
?>
However my output for getchoices.php
is just Array ( )
I have implemented the solution below, with the correct output from the console, however the PHP is not displaying anything.
No need to stringify the data.Just try like this
$.ajax({
type: "POST",
url: "getchoices.php",
dataType: 'json',
data: { "userName": "test1", "password" : "test2" }
});
And in getchoices.php
//$_POST['userName'] = test1;
//$_POST['password'] = test2;
$json = $_POST;
echo json_encode($json);
use this php function json_encode
$test = array('foo' => 'bar');
echo json_encode($test);