jquery ajax回调不起作用

时间:2013-02-20 11:13:21

标签: javascript spring jquery callback

我希望通过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;
             }

当我使用firebug时,响应为HTTP Status 404 - /ProjectCapexMonitoring/WEB-INF/views/81723.jsp

81723是我输入的输入.jsp已添加,并提供此异常。

请帮助我解决问题并解决问题。

最诚挚的问候。

1 个答案:

答案 0 :(得分:1)

如果你期待json的反应和  你的班级路径中有杰克逊罐子

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