Spring MVC,Jquery自动完成不工作
我正在尝试使用SpringMVC和Jquery实现自动完成特性;未调用控制器的函数。 请参阅下面的代码 empDeatils.jspSpring MVC,Jquery自动完成不工作,jquery,spring,model-view-controller,autocomplete,annotations,Jquery,Spring,Model View Controller,Autocomplete,Annotations,我正在尝试使用SpringMVC和Jquery实现自动完成特性;未调用控制器的函数。 请参阅下面的代码 empDeatils.jsp `link rel="stylesheet" type="text/css" ` `href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" /> ` `<script type="text/javascript" src="http:/
`link rel="stylesheet" type="text/css" ` `href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
`
`<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
`
`<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
`
`<script type="text/javascript">
`
$(document).ready(function() {
$(document).ready(function() {
$("#empName").autocomplete({
source: '${pageContext.request.contextPath}/getEmpList'
});
});
</script>
<form:input path="empName" cssClass="input-xlarge" id="empName" />
`link rel=“stylesheet”type=“text/css”`href=”http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
`
`
`
`
`
`
`
$(文档).ready(函数(){
$(文档).ready(函数(){
$(“#empName”).autocomplete({
来源:“${pageContext.request.contextPath}/GetTempList”
});
});
控制器类
@RequestMapping(value = "/getEmpList", method = RequestMethod.GET, headers = "Accept=*/*")
public @ResponseBody List<String> getEmpNameList(@RequestParam("term") String query) {
List<String> empList = empDetailsService.getEmpNames(query);
return empList;
}
@RequestMapping(value=“/getEmpList”,method=RequestMethod.GET,headers=“Accept=*/*”)
public@ResponseBody List getEmpNameList(@RequestParam(“term”)字符串查询){
List empList=empDetailsService.getEmpNames(查询);
返回雇主;
}
请帮忙
谢谢我想您忘记了自动完成的url中的控制器映射 我希望你的控制器类是这样的
@Controller
@RequestMapping("/myController")
public EmpController {
...
@RequestMapping(value = "/getEmpList" method = RequestMethod.GET, headers = "Accept=*/*")
public @ResponseBody List<String> getEmpNameList(@RequestParam("term") String query) {
List<String> empList = empDetailsService.getEmpNames(query);
return empList;
}
}
@控制器
@请求映射(“/myController”)
公共环境管理主任{
...
@RequestMapping(value=“/getEmpList”method=RequestMethod.GET,headers=“Accept=*/*”)
public@ResponseBody List getEmpNameList(@RequestParam(“term”)字符串查询){
List empList=empDetailsService.getEmpNames(查询);
返回雇主;
}
}
然后您必须使用此urlmyController/getEmpList
或${pageContext.request.contextPath}/myController//getEmpList
如果这不能解决问题,那么使用firebug之类的工具查看客户端发送的内容和服务器返回的内容。您的控制器类中是否有RequestMapping注释?尝试在控制器上添加RequestMapping,但没有用。当我在文本框中键入任何字母时,它根本不会击中控制器;我如何查看请求和返回响应。我从网络上的某个示例中引用了此代码,该示例正在运行,但不知道为什么不运行。请帮助。感谢一个查看请求的工具firebug(一个firefox插件)。它有网络选项卡,显示流量()