Jquery bootstrap3typeahead-Ajax
我正在使用 我的代码:Jquery bootstrap3typeahead-Ajax,jquery,ajax,twitter-bootstrap,bootstrap-typeahead,Jquery,Ajax,Twitter Bootstrap,Bootstrap Typeahead,我正在使用 我的代码: <input type="text" class="typeahead" autocomplete="off"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script> $(document).ready(function() { $('.typeahead').typeahe
<input type="text" class="typeahead" autocomplete="off">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('.typeahead').typeahead({
autoSelect: true,
minLength: 2,
delay: 400,
source: function (query, process) {
$.ajax({
url: '/search/searchCities',
data: {q: query},
dataType: 'json'
})
.done(function(response) {
console.log(response.data);
return process(response.data);
});
}
});
});
</script>
通过php代码
<?= echo json_encode(["status" => "OK", "data" => ["Moscow", "New York", "Odessa"]]) ?>
我看到了带有“莫斯科”选项的下拉列表,我可以选择它,如果我没有在控制台中得到错误,一切都会很好。
请告诉我我的错误
我尝试使用jquery.js(而不是min版本)。错误是
TypeError: elems is undefined
length = elems.length,
jquery.js (row 459, col 4)
我猜数据类型有问题,但我自己找不到。结果是bootstrap3-typeahead.min.js中有一个错误 如果我使用bootstrap3-typeahead.js-浏览器控制台中没有错误。行
$.ajax({
应该是返回$.ajax({
GET http://localhost/search/searchCities?q=mo 200 OK
TypeError: a is undefined
...rep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==...
jquery.min.js (row 2, col 3476)
["Moscow"]
TypeError: elems is undefined
length = elems.length,
jquery.js (row 459, col 4)