I have this code:
<script type="text/javascript">
var direcciones = [];
function getDirecciones()
{
$.ajax({
url: "getDireccionesJSON.php",
success: function (data)
{
if (data != 0)
{
var datos = jQuery.parseJSON(data);
for(var i = 0; i < datos.length; i++)
{
var dato = { "sitio" : datos[i]["sitio"], "direccion" : datos[i]["direccion"] }
direcciones.push(dato);
}
}
else
alert("No se pudo leer el json");
}
});
for(var i = 0; i < direcciones.length; i++)
document.write("Sitio: " + direcciones[i]["sitio"] + " Dirección: " + direcciones[i]["direccion"] + "<br>");
}
getDirecciones();
</script>
Why, when I get to the second cycle for to go through the array, does it indicate that there are no elements, if it is assumed that in the first cycle for insert in that array the data that came in the json ??