I need to pass a JSON object from $.post() jQuery function to PHP page.
I tried this plugin jquery-json, but don't work:
//include jquery.js and jquery.json.js
$(document).ready(function(){
var data = new Object();
data.hello = "Hello";
data.world = "World";
var datajson = $.toJSON(data);
$.post('file.php', {data: datajson}, function(res){
alert(res);
});
});
And file.php has this simple line:
<?
var_dump(json_decode($_REQUEST['data'], true));
?>
What's the problem ?