【发布时间】:2015-06-03 07:40:40
【问题描述】:
如何从 ajax 中动态生成的字段发送多个数据?
因为我无法提前知道字段的数量,所以我使用了一个对我不起作用的 for 循环。
$.ajax({
type: 'GET',
data:{
expectationPercentagePairId: JSON.stringify(expectationPercentagePairIds),
expectationScores: expectationScores,
for(var id in expectationPercentagePairIds){
score-${id}: $("input[name='score-'+id]")
}
},
url:'${g.createLink( controller:'review', action:'saveReview', params:[id: params.id] )}'
});
【问题讨论】:
-
你可以将数据作为数组/json传递
-
字段名称不同。我可以传递带有数据来源字段名称的数组吗?
-
这个expectPercentagePairIds的内容是什么?
-
它是一个数组,字段名称是score-id。这里 id 是一个变化的值。
-
你仍然可以发送它,expectationPercentagePairIds :expectationPercentagePairIds