好认真在这里挣扎.我试图通过ajax向PHP发送多维数组时遇到一些问题.这是我一直在尝试的:
为了简化而不是复制粘贴代码墙:
peoplearray[0] = [name] => 'john'
[age] => '28'
[sex] => 'Male'
peoplearray[1] = [name] => 'julie'
[age] => '20'
[sex] => 'Female'
main_array['item'] = 'x';
main_array['something'] = 'x';
main_array['another'] = 'x';
Run Code Online (Sandbox Code Playgroud)
我希望通过这个获得这个post.我想我也可以将它们加在一起,因为我是多维的,因此:
main_array['peoplearray'] = peoplearray;
Run Code Online (Sandbox Code Playgroud)
现在要做ajax:
// var data = JSON.stringify(main_array);
var send = $.ajax({
type: "POST",
cache: false,
url: "theurl",
data: {data:main_array} //I do change this `main_array` when using the above stringify!
});
send.done(function(msg) {
console.log(msg);
})
Run Code Online (Sandbox Code Playgroud)
在PHP中,我现在正在执行以下操作:
$data= $_POST['data'];
print_r($data);
Run Code Online (Sandbox Code Playgroud)
在萤火虫: (an empty string) …