2016-11-11 95 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"; 
}); 
相关问题