0

我想通过ajax调用获得一个值,这就是我所做的,

<input type="text" id="CIMtrek_CI_CER" name="CIMtrek_CI_CER" onblur="getProjectInfo()"/>

这就是我的剧本,

function getProjectInfo(){
    var cerNo = document.getElementById('CIMtrek_CI_CER').value;
     $.ajax({
         type: "POST",
         url: "CIMtrek_Project_Information",
         data: {
             cerNo: cerNo
         },
         success: function (msg) {
             alert("msg : "+msg);
             document.getElementById('div_CIMtrek_CI_Used_By_ProjNo').innerHTML=msg;
         }
     });
}

这就是我的弹簧方法:

 @RequestMapping(value = "/CIMtrek_Project_Information", method = RequestMethod.POST)
    public String getProjectInfotmation(@RequestParam("cerNo") String cerNo,HttpServletRequest request,HttpServletResponse response) throws Exception {
        System.out.println("cerNo : "+cerNo);

        return cerNo;
    }

controll 转到此方法并打印该值,但它不会在我分配该值的回调中复制。

success: function (msg) {
                 alert("msg : "+msg);
                 document.getElementById('div_CIMtrek_CI_Used_By_ProjNo').innerHTML=msg;
             }

当我使用萤火虫时,响应是HTTP Status 404 - /ProjectCapexMonitoring/WEB-INF/views/81723.jsp

81723是添加了我使用此输入提供的输入.jsp并给出了此异常。

请帮助我解决问题和解决方案。

最好的祝福。

4

1 回答 1

1

如果您期待 json 响应并且在您的类路径中有 jackson jars

添加@ResponseBody到您的方法中

改变

@RequestMapping(value = "/CIMtrek_Project_Information", method = RequestMethod.POST)
public String getProjectInfotmation(@RequestParam("cerNo") String cerNo,HttpServletRequest request,HttpServletResponse response) throws Exception {
    System.out.println("cerNo : "+cerNo);

    return cerNo;
}

@RequestMapping(value = "/CIMtrek_Project_Information", method = RequestMethod.POST)
public @ResponseBody String getProjectInfotmation(@RequestParam("cerNo") String cerNo,HttpServletRequest request,HttpServletResponse response) throws Exception {
    System.out.println("cerNo : "+cerNo);

    return cerNo;
}
于 2013-02-20T11:23:49.840 回答