$(document).ready(function() { var enumerations = {}; $.ajax({ url: "http://localhost:8080/api/nomenclatures/businessTypes" }).then(function(data) { enumerations = data; var $el = $("#companyType"); //$el.empty(); // remove old options $.each(data, function(index, obj) { $el.append($("") .attr("value", obj.value).text(obj.text)); }); }); $("#companyType").change(function() { var selectedVal = $(this).find(':selected').val(); var selectedText = $(this).find(':selected').text(); alert(JSON.stringify(enumerations[selectedVal-1])); }) }); document.addEventListener('DOMContentLoaded', e => { $('#input-prefetch').autocomplete() }, false);