我的JavaScript代码无法连接到Spring控制器:
$(document).ready(function () {
$('#nombrePais').autocomplete({
serviceUrl: 'getTags',
paramName: "tagName",
delimiter: ",",
minLength: 3,
transformResult: function (response) {
return {
suggestions: $.map($.parseJSON(response), function (item) {
return {
value: item.nombre,
data: item.idPais
};
})
};
}
});
});
我在控制器中尝试了两个:${pageContext.request.contextPath}/getTags
和getTags
。
@RequestMapping(value="getTags", method=RequestMethod.GET)
public @ResponseBody
List <Pais> getTags(@RequestParam String tagName) {
try {
System.out.println("Entre :)");
List <Pais> paises = timbreDAO.findAllPaises(tagName);
return paises;
} catch (Exception e) {
e.printStackTrace();
return null;
}
答案 0 :(得分:0)
尝试使用this.its适合我
<script type="text/javascript">
$(document).ready(function() {
$('#tsrId').autocomplete({
serviceUrl: 'YOUR_URL.html',
paramName: "tagName",
delimiter: ",",
transformResult: function(response) {
return {suggestions: $.map($.parseJSON(response), function(item) {return { value: item.name, data: item.id };
})};}});});
</script>
在春天
@RequestMapping(value = "/YOUR_URL", method = RequestMethod.GET)
public @ResponseBody List<TSRMaster> getTsrId(@RequestParam String tagName) {
----------
return tsrMasterList;
}