0

我在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.

请帮我解决这个问题。

此致。

4

1 回答 1

1

尝试这个

改变

 projectInforamtionMap = ds.getProjectInformation(cerNo);

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

在您的 ajax 调用中添加

contentType: 'application/json',

dataType : 'json',
于 2013-02-20T12:54:41.927 回答