$(function () {
$('.typeahead').typeahead({
hint: true,
highlight: true,
minLength: 3
},
{
valueKey: 'id',
displayKey: 'id',
source: function (request, response) {
$.ajax({
url: '/WebServiceASMXs/GetSL8CustVend.asmx/GetVendors',
data: "{ 'prefix': '" + request + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data.d, function (item) {
return ([{id: item.split('|')[0], name: item.split('|')[1]}])
}))
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
templates: {
suggestion: function (x) {
console.log(x)
}
}
});
})
</script>
<div class="page-header">
<h3><%= Page.Title%></h3>
</div>
<div class="row"></div>
<div id="the-basics">
<input class="typeahead form-control input-sm" type="text" />
</div>
I am use this plugin, however it keeps not working for me.
I get data back from the server, i am able to see that when i return a response from the source.
return ([{id: item.split('|')[0], name: item.split('|')[1]}])
this works, i am able to set an alert here and see the data, but it still doesn't produce a dropdown with the results. if I add a template for no data, it will trigger that template and show as if I have not recieved data.
Not sure what I am missing.