我想在 Jquery 中创建一个 Json 数据。
因为我正在这样做。我得到错误代替 "customParam'+i+'Key:"
var counter=4;
var data;
for(i=1; i<counter; i++){
data = {
"Param'+i+'Key:" : $('#key' + i).val(),
"Param'+i+'Value:" : $('#value' + i).val()
};
}
执行循环操作后,我的数据将是
data={
"Param1Key": testkey
"Param1Value": ttestval
"Param2Key":testkey
"Param2Value": testval
"Param3Key":testkey
"Param3Value": ...
"Param4Key":...
"Param4Value": ...
};
我也想追 "job": $('#job').val(),"names": $('#names').val()
加到。data
怎么可能???
我的结果数据将如下所示
数据={
"job": $('#job').val(),
"names": $('#names').val(),
"Param1Key": testkey,
"Param1Value": ttestval,
"Param2Key":testkey,
"Param2Value": testval,
"Param3Key":testkey,
"Param3Value": ...,
"Param4Key":...,
"Param4Value": ...,
};
$.ajax({
type: 'post',
url: "/save",
dataType: "json",
data: data,
});