I am trying to use jquery autocomplete with spring mvc I am using spring 3.2.3 jars along with jackson-mapper-asl-1.9.7 jackson-datatype-json-org-2.0.2 jackson-core-asl-1.9.7 jackson-core-2.0.2 for my application.
<script type="text/javascript">
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
$(document)
.ready(
function() {
$("#userName")
.autocomplete(
{
minLength : 2,
source : '${pageContext. request. contextPath}/get_country_list.htm'
});
$("#technologies")
.autocomplete(
{
source : function(request,
response) {
$
.getJSON(
"${pageContext. request. contextPath}/get_tech_list.htm",
{
term : extractLast(request.term)
}, response);
},
search : function() {
// custom minLength
var term = extractLast(this.value);
if (term.length < 1) {
return false;
}
},
focus : function() {
// prevent value inserted on focus
return false;
},
select : function(event, ui) {
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms
.join(", ");
return false;
}
});
});
</script>
and my controller goes like this
@RequestMapping(value = "/get_country_list", method = RequestMethod.GET, headers = "Accept=*/*")
public @ResponseBody
List<String> getCountryList(@RequestParam("term") String query) {
List<String> countryList = dummyDB.getCountryList(query);
System.out.println("aotuController"+query);
if(!countryList.isEmpty())
{
System.out.println(countryList.get(0));
}
return countryList;
}
@RequestMapping(value = "/get_tech_list", method = RequestMethod.GET, headers = "Accept=*/*")
public @ResponseBody
List<String> getTechList(@RequestParam("term") String query) {
List<String> countryList = dummyDB.getTechList(query);
return countryList;
}
its showing error 406 not acceptable while running.