0
<script src="http://yui.yahooapis.com/3.12.0/build/yui/yui-min.js"></script>
<script src="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’t identify because damn it I can’t capture the json values by the for.
<?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));
What is the result of
console.log(JSON)
?– Woss
[{"idDisciplina":"13","Name":"Matematica"},{"idDisciplina":"14","Name":"Portugues"},{"idDisciplina":"15","Name":"Geography"}]
– Esdras Fragoso
Then it shouldn’t be
JSON[i].idDisciplina
instead ofJSON[i][0]
?– Woss
If I place JSON[i][0] the result is [
cadastroQuestao.php:136 {
cadastroQuestao.php:136 "
cadastroQuestao.php:136 i
cadastroQuestao.php:136 d
cadastroQuestao.php:136 D
cadastroQuestao.php:136 i
cadastroQuestao.php:136 s
cadastroQuestao.php:136 c
cadastroQuestao.php:136 i
registration.php:136 p registration.php:136 l registration.php:136 i it puts a letter in each line and keeps bouncing.
– Esdras Fragoso
If I put JSON[i]. idDiscipline arises as a result 136 Undefined
– Esdras Fragoso
You putting
"<option value="+JSON[i].idDisciplina+">" + JSON[i].Nome + "</option>"
does not solve the problem?– Juven_v