使用jquery ajax在spring中在responsebody中返回HashMap时出现HTTP 406异常

时间:2013-02-20 12:31:05

标签: spring jquery spring-mvc callback

我在spring控制器中有这个方法,它返回哈希映射。

@RequestMapping(value = "/CIMtrek_Project_Information", method = RequestMethod.POST)
    public @ResponseBody Map<String,String> getProjectInfotmation(@RequestParam("cerNo") String cerNo,HttpServletRequest request,HttpServletResponse response) throws Exception {
        DataService ds = new DataService();
        Map<String,String> projectInforamtionMap = new HashMap<String,String>();
        projectInforamtionMap = ds.getProjectInformation(cerNo);
        System.out.println("projectInforamtion : "+projectInforamtionMap);
        return projectInforamtionMap;
    }

这是我使用的jquery ajax方法:

function getProjectInformation(){
    var cerNo = document.getElementById('CIMtrek_CI_CER').value;
     $.ajax({
         type: "POST",
         url: "CIMtrek_Project_Information",
         data: {
             cerNo: cerNo
         },
         success: function (projectInforamtionMap) {
             if(projectInforamtionMap.norecord !="yes"){
                 document.getElementById('projectNo').innerHTML=projectInforamtionMap.CI_Used_By_ProjNo;
                 document.getElementById('CIMtrek_CI_Used_By_ProjNo').value=projectInforamtionMap.CI_Used_By_ProjNo;

                 document.getElementById('projectName').innerHTML=projectInforamtionMap.CI_Used_By_ProjName;
                 document.getElementById('CIMtrek_CI_Used_By_ProjName').value=projectInforamtionMap.CI_Used_By_ProjName;

                 document.getElementById('projectManager').innerHTML=projectInforamtionMap.CI_Used_By_ProjMgr;
                 document.getElementById('CIMtrek_CI_Used_By_ProjMgr').value=projectInforamtionMap.CI_Used_By_ProjMgr;

                 document.getElementById('projectStatus').innerHTML=projectInforamtionMap.CI_Used_By_Status;
                 document.getElementById('CIMtrek_CI_Used_By_Status').value=projectInforamtionMap.CI_Used_By_Status;

                 document.getElementById('projectBDM').innerHTML=projectInforamtionMap.CI_Used_By_BDM;
                 document.getElementById('CIMtrek_CI_Used_By_BDM').value=projectInforamtionMap.CI_Used_By_BDM;

                 document.getElementById('projectITPlan').innerHTML=projectInforamtionMap.CI_Used_By_IT_Plan;
                 document.getElementById('CIMtrek_CI_Used_By_IT_Plan').value=projectInforamtionMap.CI_Used_By_IT_Plan;

                 document.getElementById('projectBucket').innerHTML=projectInforamtionMap.CI_Used_By_IT_Bucket;
                 document.getElementById('CIMtrek_CI_Used_By_IT_Bucket').value=projectInforamtionMap.CI_Used_By_IT_Bucket;
             }

         }
     });
}

但我在回调期间得到了这个回复;

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

请帮我解决这个问题。

最诚挚的问候。

1 个答案:

答案 0 :(得分:1)

试试这个

更改

 projectInforamtionMap = ds.getProjectInformation(cerNo);

projectInforamtionMap.put("projectInforamtionMap", ds.getProjectInformation(cerNo));

在你的ajax电话中添加

contentType: 'application/json',

dataType : 'json',