如何从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] )}'
});
发布于 2015-06-03 07:52:09
循环在这里是行不通的。您可以使用序列化传递所有表单数据,然后在后端处理数据。
$.ajax({
type: 'GET',
data:{
$('form').serialize()
},
url:'${g.createLink( controller:'review', action:'saveReview', params:[id: params.id] )}'
});
发布于 2015-06-03 08:03:45
如果动态生成的字段位于静态父元素中,则可以找到所有输入(如$("#perantelem").find('input')
),然后可以使用id(得分-${id})进行筛选,并生成键/值(name: value)数组或json。
https://stackoverflow.com/questions/30613768
复制相似问题