Skip to content

Instantly share code, notes, and snippets.

@internoma
Created May 20, 2013 18:53
Show Gist options
  • Save internoma/5614419 to your computer and use it in GitHub Desktop.
Save internoma/5614419 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"
}
@ZoramPL
Copy link

ZoramPL commented May 31, 2023

Ok line 22 and 23, whats Is 'data'?, I mean, do you refer to sonting ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment