2011-05-10 21 views
0

看起來我沒有管理讓我的Spring方法與Jquery腳本一起工作。這裏是方法JQuery onBlur腳本仍然不能與方法

@RequestMapping(value="vsfill.html", params = "accountId", method = RequestMethod.GET) 
public @ResponseBody String getAccount(@RequestParam("accountId") String accountId) throws JSONException { 
    logger.debug("getAccount() accountId "+accountId); 

    String json = null; 
    String _json = null; 

      User user = idmClient.getUser(accountId); 

       HashMap hm = new HashMap(); 
       hm.put("accoountId", user.getAccountId()); 
       //hm.put("givenName", user.getGivenName()); 
       hm.put("callingName", user.getCallingName()); 
       hm.put("email", user.getEmail()); 
       json = JsonUtils.javaToStr(hm); 


    return json; 
} 

}

腳本

 $("#person").blur(function() { 
    var accountId =$('#person').val(); 
    $.ajax({ 
    type: 'GET', 
    url: 'vsfill.html?accountId='+accountId, 
    dataType: 'json', 
    data: (accountId), 
    success: function(data) { 


     if (data!=null&&data!='') { 
      $('#responsableName').val(data.callingName); 
      $('#resposableMail').val(data.Mail); 
     } 
     }}); 
    }); 

我是個新手。

+0

'resposableMail'>在這裏輸入錯字。 'logger.debug(「getAccount()accountId」+ accountId);' - >這得到了loggeed? – ariel 2011-05-10 09:41:52

回答

0

更換

url: 'vsfill.html?accountId='+accountId, 
dataType: 'json', 
data: (accountId), 

woth

url: 'vsfill.html', 
dataType: 'json', 
data: {accountId: accountId}, 
0
  1. .VAL()不會 標籤......他們只用輸入 元素攜手。所以我認爲 $('#responsableName').val(data.callingName); 是錯誤的。

    你應該嘗試: $('#responsableName').text(data.callingName);

    來源: [http://api.jquery.com/text/][1]

    [1]:http://api.jquery.com/text/


  1. 您的數據沒有正確發送到服務器 ,因爲它不保存 任何名稱。它必須有一個名字,如 「person = Bob」。要發送這種方式,你 必須發送您的數據爲:{ 關鍵:值}格式在jQuery中。所以 變化數據部分=>數據:{ 帳戶ID:帳戶ID}

編輯:試試下面的代碼:

$("#person").blur(function() { 
    var accountId =$('#person').val(); 
    $.ajax({ 
     type: 'GET', 
     url: 'vsfill.html', 
     dataType: 'json', 
     data: {accountId:accountId}, 

     success: function(data) 
     {  
      if (data!=null && data!='') 
      { 
       $('#responsableName').text(data.callingName); 
       $('#resposableMail').text(data.email); 
      } 
     } 
    }); 
}); 

最有可能有一些語法錯誤(如額外的括號) ,其中的代碼不起作用。

+0

accountId是否真的從人員領域獲得價值?通過這些修改它仍然不起作用。 – mjgirl 2011-05-10 10:49:38

相關問題