我试图在执行 ajax 请求后返回 bootstrap typeahead 的结果,但它不起作用但是当我不启动 ajax 请求时它确实起作用。
这不起作用:
$(".typeahead").typeahead({
source: function(query, process) {
return $.ajax({
url: "/typeahead",
type: "GET",
data: "action=" + query,
success: function(result) {
return result; // this returns an array checked with console
}
});
}
});
没有ajax它可以工作:
$(".typeahead").typeahead({
source: function(query, process) {
return ["option1", "option2", "option3"]
}
});