If I want to send an array from PHP to JavaScript, I do something like this with PHP:
<?php
$json=array();
$json['datetime']="Something";
$json['timestamp']="Something else"
$encoded=json_encode($json);
die($encoded);
?>
And this on jQuery/JavaScript (using Ajax):
...
success: function(response){
var chat = jQuery.parseJSON(response);
datetime=chat['datetime'];
timestamp=chat['timestamp'];
...
I was about wondering about doing the opposite.
In jQuery i have this array:
data_send['username']=$(".chat_username").val();
data_send['message']=$(".chat_message").val();
I want to encode this array as a JSON object, send this object via Ajax, and then take this object from $_POST/$_GET and decode it to an array.
How can I do this?