Lee un archivo json y añade la lista de opciones a un elemento select
Reading json file and append list options into element select
Lee un archivo json y añade la lista de opciones a un elemento select
Reading json file and append list options into element select
<!DOCTYPE html> | |
<html lang="es-ES"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Json & Jquery</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
</head> | |
<body> | |
<h1>Json & Jquery</h1> | |
<select id="usuarios"></select> | |
<script type="text/javascript"> | |
$(document).on('ready',function (){ | |
$.getJSON('usuarios.json', function(data) { | |
$.each(data, function(key, value) { | |
$("#usuarios").append('<option name="' + key + '">' + value + '</option>'); | |
}); // close each() | |
}); // close getJSON() | |
}); | |
</script> | |
</body> | |
</html> |
{ | |
"key0": "Nombre de usuario...", | |
"key1": "Alfredo", | |
"key2": "Silvia", | |
"key3": "Mariano", | |
"key4": "Santiago", | |
"key5": "Lorenzo", | |
"key6": "Ana Belén", | |
"key7": "Cristina", | |
"key8": "Sonia" | |
} |
Ok line 22 and 23, whats Is 'data'?, I mean, do you refer to sonting ?