阿贾克斯引导多选
问题描述:
我有对我的多选举的插件 我从查询
try {
$sql = "SELECT Turma, idEscola FROM turmas WHERE (Estado = 1 AND idEscola =:val) ORDER BY Turma ASC;";
$query = $DB_con->prepare($sql);
$query->bindparam(":val", $visitaEscola);
$query->execute();
$result = $query->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
echo "<option value='{$row['idTurma']}'>{$row['Turma']}</option>\n";
}
} catch (PDOException $e) {
echo $e->getMessage();
}
让我的数据和该查询的问题
通过Ajax调用
var turmasVisita = $(this).val();
$.ajax({
type: 'POST',
url: '/miga/db/getFromDatabase.php',
data: {get_option_escola_turma: turmasVisita},
dataType: 'html',
success: function (resposta) {
console.log(resposta);
document.getElementById("turmas").innerHTML = resposta;
$('#turmas').multiselect('rebuild');
}
});
称为问题是当我检查控制台日志我得到这
<option value="">1ºA</option>
<option value="">1ºB</option>
<option value="">2ºA</option>
所以我没有选择N值
而且使用的var_dump我有
{ ["Turma"]=> string(4) "1ºA" ["idEscola"]=> string(1) "1" } 1ºA array(2) { ["Turma"]=> string(4) "1ºB" ["idEscola"]=> string(1) "1" } 1ºB array(2) { ["Turma"]=> string(4) "2ºA" ["idEscola"]=> string(1) "1" } 2ºA array(2) { ["Turma"]=> string(4) "2ºB" ["idEscola"]=> string(1) "1" } 2ºB array(2) { ["Turma"]=> string(4) "3ºA" ["idEscola"]=> string(1) "1" } 3ºA array(2) { ["Turma"]=> string(4) "3ºB" ["idEscola"]=> string(1) "1" } 3ºB array(2) { ["Turma"]=> string(4) "3ºC" ["idEscola"]=> string(1) "1" } 3ºC array(2) { ["Turma"]=> string(4) "4ºA" ["idEscola"]=> string(1) "1" } 4ºA array(2) { ["Turma"]=> string(4) "4ºB" ["idEscola"]=> string(1) "1" }
所以我的问题是,为什么我不是Ajax调用后收到idTurma场?
UPDATE
的Html
<div class="form-group">
<label for="recipient-name" class="control-label">Turmas participantes</label>
<select name="turmas[]" id="turmas" class="form-control" multiple="multiple">
<option value=""></option>
</select>
</div>
答
代替这个你得到的值10,并且在循环中指定idTurma
作为键,只需在您的循环中更改如下,然后尝试。
foreach ($result as $row) {
echo "<option value='{$row['idEscola']}'>{$row['Turma']}</option>\n";
}
答
你有错误在这行
echo "<option value='{$row['idTurma']}'>{$row['Turma']}</option>\n";
在您的查询与
echo "<option value='".$row['idTurma']."'>".{$row['Turma']}."</option>\n";
在这里显示你的HTML代码 –
检查更新请 – gmc1972