<!DOCTYPE html>
<html>
<head>
<script data-require="jquery@*" data-semver="3.0.0" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script>
<link rel="stylesheet" href="style.css" />
<script type="text/JavaScript">
$select = $('#people');
//request the JSON data and parse into the select element
$.ajax({
type:'GET',
url: 'simple.json',
dataType:'JSON',
success:function(data){
//clear the current content of the select
$select.html('');
//iterate over the data and append a select option
$.each(data.person, function(key, val){
$select.append('<option >' + val.firstName+ '</option>');
})
},
error:function(){
//if there is an error append a 'none available' option
$select.html('<option >none available</option>');
}
});
</script>
</head>
<body>
<select id="people"></select>
</body>
</html>
Los datos del archivo json local no se pueden leer usando jQuery ajax.
Incluso estoy probando el mismo código usando $.getjson()
. La salida no se devuelve.
Este es mi plunker: https://plnkr.co/edit/Ys2xxOn1oUCeNL3wqcvJ?p=preview
cambiar data.person
a data.employees
, envolver el código en una declaración de documento listo
Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.
En caso de infracción, por favor [email protected] Eliminar
Déjame decir algunas palabras