1

The Ajax call returns the following JSON:

enter image description here

Everything seems good. But when I try to access any of that content, it returns undefined.

success: function (respuesta){
   alert(respuesta.datos[0].cod_registro);
}

Even attributes like status or success return undefined. Any idea why that is? I'm not sure what I can post to help you.

xdan
  • 93
  • 11
  • 1
    respuesta.datos[0] is an object. So you have to loop. Something like respuesta.datos[0][0] – Linga Oct 11 '21 at 16:14
  • 1
    respuesta.datos is an array of arrays of objects, so you'd need respuesta.datos[0][0] to access the first object. The duplicate goes into detail how to iterate over such a structure – Kevin B Oct 11 '21 at 16:32
  • You're right. I can't believe that was the problem all along. – xdan Oct 11 '21 at 16:37

1 Answers1

0

respuesta.datos is an array of objects, so the syntax to access one of them should be something like respuesta.datos[0].cod_registro.

kmoser
  • 8,780
  • 3
  • 24
  • 40