简体   繁体   English

jQuery ajax回调不起作用

[英]jquery ajax callback is not working

i want to get a value through ajax call this is how i have done, 我想通过ajax调用获取价值,这就是我所做的,

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

and this is what is my script, 这就是我的剧本,

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

and this is what is my spring method : 这就是我的spring方法:

 @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 goes to this method and prints the value also but it does not replicate in call back where i have assigned the value. controll转到此方法并打印该值,但不会在我已为其分配值的回调中复制。

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

when i have used firebug the response is HTTP Status 404 - /ProjectCapexMonitoring/WEB-INF/views/81723.jsp 当我使用Firebug时,响应为HTTP Status 404 - /ProjectCapexMonitoring/WEB-INF/views/81723.jsp

81723 is the input i gave with this input .jsp is added and gives this exception. 81723是我给这个输入的输入.jsp加入并给出了这样的例外。

Please help me to fine what is the and resolve. 请帮助我解决问题并解决。

Best Regards. 最好的祝福。

If you are expecting json response and have jackson jars in your classpath 如果您期望json响应并且在classpath中有杰克逊罐子

add @ResponseBody to your method @ResponseBody添加到您的方法

change 更改

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

to

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM