我在jquery.autocomplete.min.js中有以下错误
TypeError:d未定义
我的home.jsp文件
<head>
<script src="<c:url value="/resources/core/jquery.1.10.2.min.js" />"></script>
<script src="<c:url value="/resources/core/jquery.autocomplete.min.js" />"></script>
<link href="<c:url value="/resources/css/bootstrap.css" />" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="vendor_input">
<input type="text" id="vendorname" path="vendorname" />
<input type="button" value="GO" />
</div>
</div>
</body>
</html>
<script type ="text/javascript">
jQuery(document).ready(function()
{
jQuery('#vendorname').autocomplete({
serviceUrl: '${pageContext.request.contextPath}/getDetails',
paramName: "vendorName",
delimiter: ",",
transformResult: function(response)
{
//alert(response);
return
{
suggestions: jQuery.map(jQuery.parseJSON(response), function(item)
{
return {value: item.vendorname, data: item.vendorid};
})
};
}
});
});
</script>
homeController.java中的函数getDetails()
@RequestMapping(value = "/getDetails",method = RequestMethod.GET,headers = "Accept=application/json; charset=UTF-8")
public @ResponseBody ArrayList<vendor> getTags(@RequestParam String vendorName)
{
System.out.println("enter into controller");
ArrayList<vendor> data = new ArrayList<vendor>();
data.add(new vendor(1, "ruby"));
data.add(new vendor(2, "rails"));
data.add(new vendor(3, "c / c++"));
data.add(new vendor(4, ".net"));
data.add(new vendor(5, "python"));
data.add(new vendor(6, "java"));
data.add(new vendor(7, "javascript"));
data.add(new vendor(8, "jscript"));
ArrayList<vendor> result = new ArrayList<vendor>();
for (vendor tag : data) {
if (tag.vendorname.contains(vendorName)) {
result.add(tag);
}
}
return result;
}
Ajax工作正常。在显示建议时我有TypeError:d是我的控制台中的未定义错误。是任何jquery版本问题。请帮助我。提前谢谢。
答案 0 :(得分:0)
不确定但是您将所有脚本放在结束</html>
之外:
</html>
<script type ="text/javascript">
你可以把它放在关闭</body>
内。