小编典典
jQuery将直接采用多维数组,而无需序列化。
var data = {
foo: 123,
bar: 456,
rows: [
{
column1 : 'hello',
column2 : 'hola',
column3 : 'bonjour',.
},
{
column1 : 'goodbye',
column2 : 'hasta luego',
column3 : 'au revoir',
},
],
test1:{
test2: {
test3: 'baz'
}
}
};
_Post PHP文件中的数据如下所示
Array
(
[foo] => 123
[bar] => 456
[rows] => Array
(
[0] => Array
(
[column1] => hello
[column2] => hola
[column3] => bonjour
)
[1] => Array
(
[column1] => goodbye
[column2] => hasta luego
[column3] => au revoir
)
)
[test1] => Array
(
[test2] => Array
(
[test3] => baz
)
)
)
定义数据多维数组后,您的Ajax可能会像
$.ajax({
type: 'post',
cache: false,
url: './ajax.php',
data: data
});
如果您的帖子数组可能包含您不知道的字段,则可以使用以下命令轻松地在php文件中访问帖子数组
$data = file_get_contents('php://input');
$data = json_decode($data, true);
2020-07-26