var data = [];
var id = 23;
var num = 12;
var dog_trialset = 15;
var cat_trialset = 23;
来自这里的问题
data.push({id:{num:num, dog_trialset:dog_trialset, cat_trialset:cat_trialset}});
ajax发布到php
[data] => Array
(
[0] => Array
(
[id] => Array
(
[num] => 12
[dog_trialset] => 15
[cat_trialset] => 34
)
)
)
我希望[id] => Array(...)
能够[23] => Array(...)
;
由于
答案 0 :(得分:1)
您可以使用下标运算符将变量用作键:
var row = {};
row[id] = {num:num,dog_trialset:dog_trialset,cat_trialset:cat_trialset};
data.push(row);