Skip to content

Instantly share code, notes, and snippets.

@Fahrek
Forked from internoma/README.mdown
Created October 15, 2019 06:42
Show Gist options
  • Save Fahrek/185e1da7c1f609ffa55b77b3593129bd to your computer and use it in GitHub Desktop.
Save Fahrek/185e1da7c1f609ffa55b77b3593129bd to your computer and use it in GitHub Desktop.
Leer JSON y rellenar control form 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"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment