我希望通过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
已添加,并提供此异常。
请帮助我解决问题并解决问题。
最诚挚的问候。
答案 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;
}