【问题标题】:Jquery AutoComplete Throws 406 Not Acceptable errorJquery AutoComplete 抛出 406 Not Acceptable 错误
【发布时间】:2014-11-12 15:19:26
【问题描述】:

我正在尝试按照此示例在我的 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>

【问题讨论】:

    标签: jquery ajax autocomplete


    【解决方案1】:

    我遇到了同样的问题,但我使用 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));
    
    }
    

    【讨论】:

      猜你喜欢
      • 2019-06-28
      • 2016-02-21
      • 1970-01-01
      • 2021-01-21
      • 2012-06-24
      • 2014-02-21
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      相关资源
      最近更新 更多