我正在寻找解决我的问题的方法。我有一堆复选框,基于它们被选中,我想将值发送到 ajax 调用。
这是我的html...
<div class="control-group ">
<label for="qualifications" class="control-label required">Qualifications</label>
<div class="controls">
<table class="table">
<tbody>
<tr>
<td>Induction</td>
<td>
<div class="switch" data-on-label="In" data-on="info" data-off-label="Out">
<input id="qual" name="qual[1]" type="checkbox" value="1">
</div>
</td>
</tr>
<tr>
<td>LearnerZone Academy</td>
<td>
<div class="switch" data-on-label="In" data-on="info" data-off-label="Out">
<input id="qual" name="qual[7]" type="checkbox" value="7">
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="control-group ">
<label for="units" class="control-label required">Units</label>
<div id="unit-holder" class="controls">
<table class="table">
<tbody>
<tr>
<td>Data Protection (DP1)</td>
<td>
<div class="switch" data-on-label="In" data-on="info" data-off-label="Out">
<input name="unit[7]" type="checkbox" value="7">
</div>
</td>
</tr>
<tr>
<td>Equal Opportunities (EQ1)</td>
<td>
<div class="switch" data-on-label="In" data-on="info" data-off-label="Out">
<input name="unit[3]" type="checkbox" value="3">
</div>
</td>
</tr>
<tr>
<td>Health & Safety (HS1)</td>
<td>
<div class="switch" data-on-label="In" data-on="info" data-off-label="Out">
<input name="unit[1]" type="checkbox" value="1">
</div>
</td>
</tr>
</tbody>
</table>
</div>
和 jQuery...
// Makes the question count
$("input[type=checkbox]").on('change', function(){
var units = $('#unit[]');
var stringy = JSON.stringify(units);
//EDIT
//I'm actually looking for both qualifications and units
var qualifications = $('#qualifications[]');
var stringy = JSON.stringify(qualifications);
$.ajax({
type: "POST",
url: "http://vle.dev/ajax/question-count",
data: {units: units, qualifications: qualifications},
dataType: "text"
}).done(function(data) {
$('.qCount').html(data);
});
});
有人能帮助我吗?