2015-03-02 91 views
-1

在我的春天MVC項目我有2個控制器,其中一個映射這樣的:AJAX錯誤的請求只有在映射控制器

@Controller() 
@RequestMapping("/draft") 

我試圖從阿賈克斯發送一些數據這樣的:

$.ajax({ 
    type : 'get', 
    url : 'http://localhost:8080/FootballManager/draft/draftplayer', 
    dataType : "json", 
    data : { 
     'playerID' : playerID, 
     'username' : username, 
     'leaguename' : leaguename 
    }, 
    response : 'text', 
    success : function(data) { 
     if (data == 1) { 
      alert("player drafted"); 
     } else { 

      alert("player not drafted"); 
     } 
    }, 
    error : function(XmlHttpRequest, textStatus, errorThrown) { 
     _requesComplete = true; 
     alert("error= " + errorThrown); 

    } 

和方法控制器:

@RequestMapping(value="/draftplayer",method = RequestMethod.GET) 
    public @ResponseBody 
    String draftPlayer(@RequestParam("playerID") int playerID, 
      @RequestParam("username") String username, @RequestParam("leaguename") String leaguename,HttpSession session) { 
     try { 
     ... 
      return "1"; 
     } catch (Exception e) { 
      return "0"; 
     } 
    } 

,我總是得到錯誤的請求,但如果我把這個方法引入另一個控制器,它沒有類參考中的@RequestMapping註釋,並將url更改爲

url : 'http://localhost:8080/FootballManager/draftplayer', 

它完美地工作。我花了很多時間來解決這個問題,爲什麼會發生這種情況? (對不起,我的英文..)

回答

0

問題解決了。我在我的控制器中有方法,如草稿/ {leaguename}映射,並且在發送草稿/草稿播放請求時,它映射到第一種方法