Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
Valor indefinido document.getElementById

tengo un problema aquí. Quiero hacer un solicitante de servicio web usando un proveedor que ya tengo. el problema es que siempre obtengo valores indefinidos para ID, Kab e ID2. ¿Puede alguien ayudarme a arreglar el código en el solicitante?

este es el proveedor

 $sql="SELECT * FROM mytable"; $query = mysqli_query($con, $sql); $result = array(); while($row = mysqli_fetch_array($query)){ array_push($result, array( 'IDKabupaten' => $row['IDKabupaten'], 'Kabupaten' => $row['Kabupaten'], 'attribut' => array( 0 => array( 'IDProvinsi' => $row['IDProvinsi'] ) ) )); } echo json_encode(array('mytable' => $result)); ?>

este es el solicitante

 <script type="text/javascript"> $.getJSON("http://localhost/json2/wsp_coba2.php", function(result){ console.log(result); $.each(result,function(i) { document.getElementById("DataKabupaten").innerHTML +="ID :" + result[i].IDKabupaten +"<br>Kab :" + result[i].Kabupaten +"<br>ID2 :" + result[i].IDProvinsi + "<br><br>"; }); }); </script>

Me estoy poniendo

 ID : undefined Kab : undefined ID2 : undefined
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

 const result = { "mytable": [ { "IDKabupaten": "3301", "Kabupaten": "CILACAP", "attribut": [ { "IDProvinsi": "33" } ] }, { "IDKabupaten": "3302", "Kabupaten": "BANYUMAS", "attribut": [ { "IDProvinsi": "33" } ] } ] }; $.each(result.mytable,function(i) { console.log(result.mytable[i].IDKabupaten); $.each(result.mytable[i].attribut, function (j) { console.log(result.mytable[i].attribut[j].IDProvinsi) }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

usted puede comprobarlo

about 4 years ago · Juan Pablo Isaza Relatório

0

Prueba esto...

 $.each(result,function(i) { document.getElementById("DataKabupaten").innerHTML +="ID :" + result[i].IDKabupaten +"<br>Kab :" + result[i].Kabupaten +"<br>ID2 :" + result[i].IDProvinsi + "<br><br>"; }); result.forEach((singleResult, index) => { // and then do your thing here. I don't use jquery but I took a quick look at their docs and your loop doesn't look right. This is the same function that jquery is calling under the hood. })

Elimina tu código... Solo lo dejé ahí para que puedas comparar.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda