为什么我得到406不可接受的回复?

时间:2018-06-13 09:25:23

标签: javascript json ajax spring spring-mvc

这是我的代码

$.ajax({

                    url: "DataGridServlet.htm",
                    type: "GET",
                    traditional: true,
                    dataType: 'JSON',
                    cache: false,
                    contentType:"application/json",
                    success: function (response){

                       console.log(response);
                   }
                   });

            });

当我向控制器发送请求时...每个都在工作但是返回JSONObject我得到的状态代码为406不可接受。

以及弹簧控制器代码

@RequestMapping(value="/DataGridServlet.htm", method = RequestMethod.GET,produces="application/json",headers="Accept=*/*")
    public @ResponseBody JSONObject getReturnData()
    {
       System.out.println("control came into conroller");
       JSONObject dataObject=new JSONObject();
       dataObject=jqTabsGridDataDao.getTabsData();
       System.out.println("controller data"+dataObject);
       return dataObject;
    }

任何人都可以帮助我?

1 个答案:

答案 0 :(得分:0)

更改

@RequestMapping(value="/DataGridServlet.htm", method = RequestMethod.GET,produces="application/json",headers="Accept=*/*")

@RequestMapping(value="/DataGridServlet.htm", method = RequestMethod.GET,produces="application/json",)

和这个

$.ajax({

                    url: "DataGridServlet.htm",
                    type: "GET",
                    traditional: true,
                    dataType: 'JSON',
                    cache: false,
                    contentType:"application/json",
                    success: function (response){

                       console.log(response);
                   }
                   });

            });

    $.ajax({
                url: 'DataGridServlet.htm',
                type: "GET",
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json'
                },
                success: function(result) {
                    alert(result + " result ");
                },
                error: function(resError) {

                    //alert(resError + " Error ");
                }
});
相关问题