对象
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);
我似乎无法使其发挥作用。帮助
答案 0 :(得分:2)
不,你似乎对此感到困惑。你不需要json_decode()
那个。一旦它在邮政体内。只需按原样访问它:
$data = $_POST['objectToBePassed'];