douwen1901 2017-07-19 09:48
浏览 41
已采纳

Ajax Bootstrap multiselect

I'm having a problem regarding my multiselect bootstrap plugin I'm getting my data from a query

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>
";
    }
} catch (PDOException $e) {
    echo $e->getMessage();
}

and this query is called by an ajax call

 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');
        }
    });

The problem is when i check the console log i'm getting this

<option value="">1ºA</option>
<option value="">1ºB</option>
<option value="">2ºA</option>

So i have no option value

And using var_dump i have

{ ["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" } 

So my question is why i'm not receiving the idTurma field after ajax call?

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>
  • 写回答

2条回答 默认 最新

  • douxiu6835 2017-07-19 09:56
    关注

    in your query you get value of idEscola and you specify idTurma in your loop as key, just change like below in your loop and try.

    foreach ($result as $row) {
            echo "<option value='{$row['idEscola']}'>{$row['Turma']}</option>
    ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题