【发布时间】:2018-06-03 06:30:17
【问题描述】:
我根据每个候选人的每个职位生成了带有名称的单选按钮。现在的问题是获取每个单选按钮的值。我的代码是这样的;
$("#btn-vote").click(function() {
$.ajax({
url: 'admin/requests/Get-Positions.php',
method: 'POST',
data: { id : id },
dataType: 'json',
success: function(result) {
var textToInsert = '';
$.each(result, function(key, value)
{
var position_id = value['id'];
$.ajax({
url: 'admin/requests/Get-Candidate_Per_Position.php',
method: 'POST',
data: { position_id : position_id },
dataType: 'json',
success: function(data) {
textToInsert += '<div class="card bg-primary text-center"><div class="card-body"><h4 class="text-white m-0" id="position">'+ value['position'] +'</h4></div></div><br><div class="row">';
$.each(data, function(key, value)
{
textToInsert += '<div class="col-lg-3 col-sm-6 text-center mb-4"><img class="rounded-circle img-responsive d-block mx-auto" src="admin/img/'+ value['photo'] +'" width="150" height="150"><br><span class="lead">'+ value['first_name'] +'</span><div class="form-check"><label class="form-check-label"><input type="radio" class="form-check-input" name="position'+ value['position_id'] +'" value="'+ value['id'] +'"></label></div></div>';
});
textToInsert += '</div>';
$('#candidate_list2').html(textToInsert);
}
});
});
},
error: function(xhr, status, error) {
console.log(xhr.responseWithJSON)
}
});
});
单选按钮是在第二个 ajax 请求中生成的,名称如位置 + 每个位置的 ID。
感谢您的宝贵时间。任何帮助将不胜感激。
【问题讨论】:
标签: jquery ajax button dynamic radio