Reputation: 8240
I am sending data from services.js coming in as a json encoded string in the following format to myPhp.php:
{"Name":"alpha"}
I want to gather this data and send back to the services.js as it came back in json form adding beta to the string as in:
{"Name":"alpha beta"}
myPhp.php
<?php
$a = $_POST[data];
$b = json_decode($a);
$c = $b.Name + "beta";
echo ($c);
?>
Upvotes: 1
Views: 38
Reputation: 1654
<?php
$a = $_POST[data];
$b = json_decode($a);
$c = $b['Name'] . " beta";
header('Content-Type: application/json');
echo json_encode($c);
?>
Upvotes: 1
Reputation: 33813
The "." notation is not used in PHP to access / set properties - more like Javascript and you need to have quotes around the $_POST
variable ~ unless data
is defined as a constant. I think you could try something like this though.
<?php
$b = json_decode( $_POST['data'],true );
$b['name'].='beta';
echo json_encode($b);
?>
Upvotes: 1