我正试图通过以下示例在我的spring mvc应用程序中创建一个自动完成框 http://www.mkyong.com/spring-mvc/spring-mvc-jquery-autocomplete-example/ 每当我尝试获取详细信息时,它会在浏览器中显示以下错误 NetworkError:406 Not Acceptable 这是我的控制器
@RequestMapping(value = "/searchTags.htm", method = RequestMethod.GET)
public @ResponseBody
List<SolrResult> getTags(@RequestParam String tagName) throws Throwable {
return fetchData(tagName);
}
这是我的POJO课程
public class SolrResult {
private String id;
private String label;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@Override
public String toString() {
return "SolrResult [id=" + id + ", label=" + label + "]";
}
}
这是我的javascript
<script>
$(document).ready(function() {
$('#inputText').autocomplete({
serviceUrl: '${pageContext.request.contextPath}/searchTags.htm',
paramName: "tagName",
delimiter: ","
transformResult: function(response) {
return {
suggestions: $.map($.parseJSON(response), function(item) {
return { value: item.label, data: item.id };
})
};
}
});
});
</script>
答案 0 :(得分:0)
我遇到了同样的问题但是我用这种方式修复了Gson():
@RequestMapping(value = "/getCustomer", method = RequestMethod.GET)
@ResponseBody String getCustomer(@RequestParam String query) {
CustomerDao customerDao = (CustomerDao) ApplicationProperty.getApplicationContext().getBean("CustomerDao");
Gson gson = new Gson();
return gson.toJson(customerDao.getCustomer(query, userProfile));
}