2013-02-20 65 views
0

我想通過Ajax調用的值,這是如何我都做了,jQuery的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輸入被加入並給出此異常。

請幫我弄清楚什麼是和解決。

最好的問候。

回答

1

如果你期待JSON響應和 有傑克遜罐子在classpath

添加@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; 
} 
+0

大它幫助我爲了解決我的問題,我會在幾個小時後接受你的答案几分鐘,它不允許我接受:) – 2013-02-20 11:29:18

+0

克里斯你在嗎? – 2013-02-20 12:26:25

+0

是剛剛登錄 – Kris 2013-02-20 12:46:34