我想实现一些功能,当我输入一些文本时
<input path="tags" id="input-search"/>
public interface TagRepository extends JpaRepository<Tag, Integer> {
@Query("SELECT t FROM Tag t WHERE name LIKE CONCAT('%', :name, '%')")
List<Tag> findTagByName(@Param("name") String name);
}
和控制器代码是
@RequestMapping(value = "/getTags", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody List<Tag> getTags(@RequestBody Tag tag, HttpServletResponse response) {
System.out.println("Found " + String.valueOf(tagService.findTagByName(tag.getName()).size()));
return tagService.findTagByName(tag.getName());
}
jj for ajax是
$(document).ready(function() {
$("#tag-search").autocomplete({
source: function(request, response) {
$.ajax({
url: "/app/getTags/",
type: "POST",
data: JSON.stringify({tag : request.term}),
dataType: "json",
success: function(data) {
response($.map(data, function(v,i){
console.log();
return {
label: v.empName,
value: v.empName
};
}));
}
});
}
});
});
<div class="col-md-10 col-md-push-1">
<label class="floating-label" for="login-username">Tags</label>
<form:input path="tags" cssClass="form-control" id="tag-search"/>
</div>
当我运行应用程序时,我在开发人员工具中看到了这个javaScript错误
重要
我正在使用Daemonite/material作为我的前端和前端jQuery-Autocomplete,最后一件好事是最新版本的App是on GitHub
谁能告诉我如何摆脱这个错误欢迎任何回复.
解决方法:
检查jquery供应商库是否正确加载.
交叉检查:
<script>
if (window.jQuery) {
alert('jQuery is loaded');
} else {
alert('jQuery is not loaded');
}
</script>