I am trying to send json in ajax using javascript. I am able to retrieve the values back from php but unable to retrieve a specific json array.
var mname = ["john", "mary", "eva"];
var fname = 678;
clicked_keyword_test = {"lastName": fname, "firstName": mname};
xmlhttp.send('myArray=' +JSON.stringify(clicked_keyword_test));
Getting data in PHP and sending it back to ajax:
$receive_data = json_decode ($_POST['myArray']);
echo json_encode($receive_data);
Now the above works fine but if I want to retrieve only the values of "firstName"
like echo json_encode($receive_data["firstName"]);
then I get an error like:
<b>Fatal error</b>: Cannot use object of type stdClass as array in.....
How can I sucessfully send json data using javascript not jquery.