Sorry if there is a decent example of this somewhere outer, I've been looking for days and can't find a solution.
Gathering data from JSON file "database.json":
"[{\"id\":\"1\",\"state\":\"Alaska\"},{\"id\":\"2\",\"state\":\"Alabama\"},{\"id\":\"3\",\"state\":\"California\"}]"
Here is my most recent attempt that failed:
$("#state").autocomplete({
source: function( request, response ) {
$.ajax({
url: "database.json",
dataType: "json",
data: {term: request.term},
success: function(data) {
console.log(data)
response($.map(data, function(item) {
return {
label: item.state,
id: item.id,
};
}));
}
});
},
minLength: 2,
select: function(event, ui) {
$('#state_id').val(ui.item.id);
}
});
And of course the html:
<input type="text" id="state"/>
I have no idea where to go from here, I just want a simple drop down autocomplete. Let me know if more information is needed and I can provide.
Thank you!
console.log(data)datais the param to the success callback... so you need to add the console logging inside the success callback just beforeresponse($.map(data, function(item) {