2016-11-11 93 views
0

是否有可能從jquery函數調用控制器方法來重定向一些描述頁面?Spring 4 MVC + Apache Tiles 3 + JQuery

例如: 首先,我有這樣的描述瓷磚頁面是這樣的:

<definition name="IndexDefinitionTiles" extends="base.definition"> 
    <put-attribute name="body" value="/WEB-INF/pages/_index.jsp" /> 
</definition> 

其次,我有打電話說明瓷磚頁面這樣的方法控制:

@RequestMapping(value = "/goingPage", produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.GET})  
public @ResponseBody String goingPage(HttpServletRequest request) { 

    //This is a definition Tiles page. 
    return "IndexDefinitionTiles"; 

} 

三,我有這個JQuery函數:

// Catch event on button. 
$("#btnCallGoingMethod").click(function (evt) { 
    //Here i wanna call the method /goingPage that redirect to IndexDefinitionTiles 
}); 

是嗎?可能?

我藉此機會問你是否可以用$ .ajax來做,我想知道它怎麼可能。

+0

這可能嗎?有誰知道? – Roldan

回答

0

在js文件的頂部把這個

var serverContext = window.location.pathname.substring(0, window.location.pathname.indexOf("/",2)); 

然後在功能

// Catch event on button. 
$("#btnCallGoingMethod").click(function (evt) { 
    window.location.href = serverContext + "/goingPage"; 
}); 
相關問題