En el código jQuery, debe tener la propiedad employees
.
data.employees[0].firstName
Así sería así.
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$.getJSON("names.json", function(data) {
console.log(data);
$('body').append(data.employees[0].firstName);
});
</script>
</body>
</html>
Por supuesto, usted necesitará que la propiedad de la versión no jQuery también, pero que había necesidad de analizar la respuesta JSON en primer lugar.
También tenga en cuenta que document.write
está destruyendo toda la página.
Si sigue teniendo problemas, pruebe el $.ajax
solicitud completa en lugar de la $.getJSON
envoltura.
$.ajax({
url: "names.json",
dataType: "json",
success: function(data) {
console.log(data);
$('body').append(data.employees[0].firstName);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('ERROR', textStatus, errorThrown);
}
});
http://api.jquery.com/jquery.ajax/
que había cambiado la pregunta y fija los errores. Ahora creo que podría recibir votaciones y sería una buena referencia para otras personas. – GarouDan