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 TMC2209串口模式下读取不到寄存器的值串口助手蓝色字体是发过去的消息,绿色字体是收到的消息,第二行发送读取寄存器的指令但是没有读取到寄存器的值串口助手如下图:接线如下图,如何解决?
  • ¥30 itest不允许查看成绩怎么办
  • ¥15 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏