Combobox人口

时间:2017-04-04 07:09:28

标签: php html mysql ajax combobox

我需要有关组合框群体的帮助(我已经将其用于其他应用程序并且它工作正常,不知道为什么这个时间不起作用)

我有以下代码:

脚本:

$(document).on('change','#pl',function(){
             var val = $(this).val();
             $.ajax({
                   url: 'justificacoes.php',
                   data: {Descricao:val},
                   type: 'GET',
                   dataType: 'html',
                   success: function(result){
                        $('#justificacao').html();  
                        $('#justificacao').html(result); 
                   }
              });
       });

然后我有:

    <select id="pl" name="pl" class="pl" width="400" style="width: 400px" required>
                <option selected value="">Supervisor</option>
                <?php


                $sql = "SELECT ID_CC, Descricao FROM cc where Activo = 1";

                $pl = mysql_query($sql);

                while($row = mysql_fetch_array($pl))
                { 
                    $ID_CC = $row['ID_CC'];
                    $Descricao = $row['Descricao'];

                    echo '<option value="'.$ID_CC.'">'.$Descricao.'</option>';
                }
                ?>
            </select>
<tr>
            <td><input id="numero" name="numero" size="20" required></td>
            <td><input id="datetimepicker" name="datetimepicker" size="20" required></td>
            <td><input id="datetimepicker1" name="datetimepicker1" size="20" required></td>
            <td><select name="justificacao" id="justificacao" class="pl" width="400" style="width: 400px" >  
                <option selected value=""></option>

                </select>
            </td>
        </tr>

最后:

$ID_CC = $_GET['Descricao'];

        //select all the stations from the selected line.
        $sqlstations = $conn->prepare('SELECT justificacoes.IDJustificacao, justificacoes.Justificacao FROM justificacoes, justificacaocc, cc  WHERE justificacaocc.IDJustificacao = justificacoes.IDJustificacao and justificacaocc.ID_CC = cc.ID_CC and cc.ID_CC = :ID_CC');
        $sqlstations->execute(array(':ID_CC' => $ID_CC));

        $_SESSION['ID_CC'] = $ID_CC;

        //run the returned data and save it into variables.
        while($row = $sqlstations->fetch(PDO::FETCH_ASSOC))
        {
            $IDJustificacao=$row['IDJustificacao'];
            $Justificacao=$row['Justificacao'];
            echo '<option value="'.$IDJustificacao.'">'.$Justificacao.'</option>';
        }

提前致谢:)

1 个答案:

答案 0 :(得分:0)

尝试按照ajax调用,

$.ajax({
   url: 'justificacoes.php?Descricao='+$(this).val(),
   type: 'GET',
   success: function(result){
     $('#justificacao').html(result); 
   }
});