Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/08/2018, 13:52
leoalvis
 
Fecha de Ingreso: febrero-2007
Mensajes: 43
Antigüedad: 17 años, 2 meses
Puntos: 0
No muestra json (ajax)

Buenas tardes... Aprendiendo Ajax estoy tratando de mostrar un sencillo json por consola pero no logro hacerlo. Se que debe ser algo minimo pero no se que puede estar fallando, He revisado linea a linea y ya no se que mas hecerle. Adjunto el codigo, muchas gracias:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<button onclick="ejecutarAjax()">Mostrar Datos</button>



<script>
function ejecutarAjax(){

var xmlhttp;

if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
let respuesta=JSON.parse(xmlhttp.responseText);
console.log(respuesta);
}
}

xmlhttp.open("GET","datos.json",true);
xmlhttp.send();


}
</script>

</body>
</html>


//datos.json


{
"nombre":"leonardo",
"edad":35
}