Object:
var obj = [{id: 1, name: "Peter", lastname: "Griffin"}]
Javascript:
$.ajax({
method: 'post',
url:'http://api/test.php',
data: {
func: "addtodatabase",
objectToBePassed: obj //also tried JSON.stringify(obj)
},
success: function(data) {
//code here
}
});
PHP:
$data = json_decode($_REQUEST['objectToBePassed'], true);
I can't seem to make it work. Help?
$_REQUEST['objectToBePassed']as you got it? And the value of$dataafter the decode? Your question lacks information about what goes wrong.