2011-03-10 96 views
0

在我的客戶端中,我使用ajax向Spring控制器發送請求。這最後可以攔截它,但是當我返回一個值時,我不能在我的客戶端沒有它。Spring-mvc和Ajax jquery:無法從服務器獲得響應

客戶端代碼:

$.ajax({ 
      type: "GET", 
      data: {name : "name"}, 
      url: "/web/private/frontend/accueil/dateHistorique.html", 
      success: function(msg){ 
       alert("Hello"); 
      } 
     }); 

服務器端代碼:

 @RequestMapping(value="/dateHistorique.html", method = RequestMethod.GET) 
public @ResponseBody Map<String, String> getAllowedDate(@RequestParam String name) { 
    System.out.println("***********************************" + name); 
    AllowedDates allowedDates = new AllowedDates("1","20"); 
    Map<String, String> responseMap = new HashMap<String, String>(); 
    responseMap.put("Name", "Marouane"); 
    return responseMap; 
} 

我能看見了放在服務器:* ** * *** *名稱但始終沒有迴應。 日Thnx

+0

'/web/private/frontend/accueil/dateHistorique.html' 正在尋找像一個文件系統路徑。確定你可以通過瀏覽器調用它? – schellmax 2011-03-10 14:20:32

+0

這只是一個映射:)它現在正在工作,我只需要返回一個可以轉換爲JSON的對象。怎麼做 ? – 2011-03-10 14:27:00

+0

不知道春天,但發現這個:http://spring-json.sourceforge.net/(取自http://stackoverflow.com/questions/1601992/sp​​ring-3-json-with-mvc) – schellmax 2011-03-10 14:35:12

回答

0

應該添加Jackson到我的POM和<mvc:annotation-driven />到我的MVC-的servlet上下文