I am trying to get the data in the dropdown in typeahead, I made the API and frontend ajax but when I input the value in textbox I am not able to see the suggestion in the dropdown. I read the threads other available on google but it was not helpful. this is below the sample code I mentioned please help me with How I get the option in typeahead when I input the value in the textbox.
$("input#userid").typeahead({
hint: true,
highlight: true,
minLength: 2
}, {
name: 'options',
displayKey: 'value',
source: function(query, process) {
return $.post("https://jsonplaceholder.typicode.com/todos/", {
keyword: query
}, function(data) {
var matches = [];
$.each(data, function(i, str) {
matches.push({
value: str.userId
});
});
return process(matches);
}, 'json');
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/typeahead.js@0.11.1/dist/typeahead.bundle.min.js"></script>
<input class="form-control" type="text" placeholder="UserID" id="userid">
my API responding me like this array :
{res: 'OK', data: {userId: "John"}}
res: 'OK'
data: {userId: "John"}
userId: "John"