<script type="text/javascript">
$(document).ready(function() {
// Initializing the typeahead
$('.typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
}, {
source: function(query, process) {
return $.get(
'http://ac.agenttm.com/v1.0/entity/'+query,
function(data) {
console.log(data);
return process(data.data);
}, 'json');
}
});
});
</script>
</head>
<body>
<div class="bs-example">
<h2>Enter your country name</h2>
<input type="text" class="typeahead tt-query" autocomplete="off" spellcheck="false">
</div>
</body>
source: function(query, process) {
return $.getJSON(
'url' + query,
function(data) {
var jsonData = data.data; //JSON файл в формате {"data":"data", "data":["data1", "data2", "data3"]}
var matches = [];
$.each(jsonData, function(i, str) {
matches.push({
value: str
});
});
return process(matches);
}, 'json');
}