Select with php javascript ajax json

0
<script src="http://yui.yahooapis.com/3.12.0/build/yui/yui-min.js"></script><scriptsrc="js/jquery-3.2.1.min.js" ></script>
        <script type="text/javascript">

   function run(){    

   var id = $("#id_Turma").val();
   console.log(id);


     $.ajax({
        url : "includes/disciplina.php/",
        type : "POST",
        data : { 
            id : id
             },
        success : function(JSON) {
            $("#idDiciplina").html("");
            console.log(JSON);



             $('#idDiciplina').append("<option value='' selected='selected'>Disciplinas</option>");

            for (var i = 0; i < JSON.length; i++) {
                $('#idDiciplina').append("<option value="+JSON[i][0]+">" + JSON[i][1] + "</option>");

            }

            }

    }); 

}

Look at the code I can not seem to identify because I can not get the json values by the way.

<?php       

 //include('../seguranca.php');

 $id_turmar = $_POST['id'];
           $consulta = DB::getConn()->prepare("SELECT idDisciplina, Nome FROM 'disciplina' WHERE Turma_idTurma = :Turma_idTurma;");
            $consulta->bindParam(':Turma_idTurma',  $id_turmar, PDO::PARAM_STR);
            $consulta->execute();
            while ($assunto = $consulta->fetch(PDO::FETCH_ASSOC))  { 

             $assunto_post[] = array(
            'idDisciplina'  => $assunto['idDisciplina'],
            'Nome' => utf8_encode($assunto['Nome']),
        );  

            }
   echo(json_encode($assunto_post));
    
asked by anonymous 26.08.2017 / 00:11

1 answer

0

Try to use for ... in:

for (j in JSON) {
   $('#idDiciplina').append(
      "<option value="+ JSON[j].idDisciplina +">" + JSON[j].Nome + "</option>"
   );
}

I do not remember if you need to use var -> for(var j in JSON){

    
26.08.2017 / 04:39