【问题标题】:Spring 4 MVC+Apache Tiles 3+JQuerySpring 4 MVC+Apache Tiles 3+JQuery
【发布时间】:2016-11-11 01:27:06
【问题描述】:

是否有可能从一个 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 来实现,我想知道它是怎么实现的。

【问题讨论】:

  • 有可能吗?有谁知道吗?

标签: jquery spring-mvc tiles


【解决方案1】:

在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";
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多