【问题标题】:Why i am getting 406 not acceptable response?为什么我得到 406 不可接受的响应?
【发布时间】:2018-11-22 19:48:14
【问题描述】:

这是我的代码

$.ajax({

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

                       console.log(response);
                   }
                   });

            });

当我向控制器发送请求时..每个都在工作但 wnem 返回 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;
    }

谁能帮帮我?

【问题讨论】:

  • 删除客户端上除 urltypesuccess 参数之外的所有内容,然后重试。
  • nooo 同样的错误来了,时间控制器没有调用

标签: javascript json ajax spring spring-mvc


【解决方案1】:

改变

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

【讨论】:

    猜你喜欢
    • 2012-12-24
    • 2014-09-27
    • 2015-05-17
    • 2011-11-19
    • 2011-11-20
    • 2019-09-01
    相关资源
    最近更新 更多