【发布时间】:2016-08-03 12:51:44
【问题描述】:
我很绝望!
我在使用 Bootstrap Typeahead 时遇到了这个问题。
HTML 标记:
<div class="form-group">
<label for="">Recipients</label>
<input id="recipients" name="recipients"
autocomplete="off"
class="form-control"
data-role="tagsinput">
</div>
JavaScript:
$('#recipientsContainer').tagsinput({
allowDuplicates: false,
trimValue: true,
confirmKeys: [13, 44],
typeahead: {
hint: true,
highlight: true,
minLength: 4,
limit: 10,
source: function (query) {
$.ajax({
url: "/app/route",
type: 'POST',
dataType: 'JSON',
data: {'query' : query},
success: function(data) {
console.log(data);
return(data);
}
});
},
afterSelect: function() {
this.$element[0].value = '';
}
}
});
Ajax 调用后,我在控制台中得到了这个数组:
["Justin Demetria +393281893574", "Dylan Alea +393700488191", "Zahir Tatyana +393007841301", "Ryan Veda +393542236060", "Hunter Wanda +393393156943"]
问题是:我什么也没看到 :( 什么也没出现。提前输入不起作用。
在控制台中,我收到此错误
bootstrap-tagsinput.js Uncaught TypeError: Cannot read property 'success' of undefined.
我该如何解决?
我正在使用 Bootstrap 3,最后一个 Typeahead js 源代码。
【问题讨论】:
标签: javascript php html mysql bootstrap-typeahead