我有Spring MVC控制器:
@Controller
@RequestMapping(value = "/bla")
public class TestController {
@RequestMapping(value = "json", method = RequestMethod.POST)
public @ResponseBody String getJson(@ModelAttribute SearchQueryJson searchQueryJson) {
System.out.println("hih");
System.out.println(searchQueryJson.getQuery());
return new String("{'asd','asdd'}");
}
}
和js:
<script>
$("#searchbox").typeahead({
source: function (typeahead, query) {
return $.post("bla/json", { query: query }, function (data) {
return typeahead.process(data);
});
}
});
</script>
在google chrome调试器中我看到响应{'asd','asdd'},但没有任何反应(搜索框中的下拉菜单没有出现)!我正在使用twitter bootstrap typeahead (method 'toLowerCase' of undefined)和https://gist.github.com/2712048
答案 0 :(得分:1)
更改return typeahead.process(data);
到return typeahead(data);