Jquery AutoComplete 抛出 406 Not Acceptable 错误 [英] Jquery AutoComplete Throws 406 Not Acceptable error

查看:26
本文介绍了Jquery AutoComplete 抛出 406 Not Acceptable 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照此示例在我的 spring mvc 应用程序中创建一个自动完成框http://www.mkyong.com/spring-mvc/spring-mvc-jquery-autocomplete-example/每当我尝试获取详细信息时,它都会在我的浏览器中显示以下错误网络错误:406 不可接受 这是我的控制器

I am trying to create an auto complete box in my spring mvc application by following this example http://www.mkyong.com/spring-mvc/spring-mvc-jquery-autocomplete-example/ Whenever I try to fetch the details it shows the following error in my browser NetworkError: 406 Not Acceptable Here is my controller

@RequestMapping(value = "/searchTags.htm", method = RequestMethod.GET)
    public @ResponseBody
    List<SolrResult> getTags(@RequestParam String tagName) throws Throwable {

        return fetchData(tagName);

    }

这是我的 POJO 课程

Here is my POJO class

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

This is my 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>

推荐答案

我遇到了同样的问题,但我使用 Gson() 解决了这个问题:

I had the same issue but I fixed using Gson(), in this way:

@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));

}

这篇关于Jquery AutoComplete 抛出 406 Not Acceptable 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆