首页 > 解决方案 > 基本 URL 在 Grails 生产模式下不起作用

问题描述

我正在使用 grails-2.4.5 版本。我的侧面菜单模板中有一些菜单链接,我在其中使用控制器名称和操作的属性。

在我的 application.js 文件中使用该属性调用 URL。它在开发模式下工作正常,并且可以正常显示每一页。但是当我运行战争时,如果我单击链接,它只会在 URL 中附加 # 符号,但不会显示页面。

我的菜单链接:

...
<li>
    <a class="action-item" controller="designation" action="index" href="#"><i class="fa fa-briefcase fa-fw"></i> Designation</a>
</li>
...

我的 JS 函数来呈现页面:

    $(document).ready(function () {
    $("a.action-item").on("click", function (e) {
        var controller = $(this).attr("controller");
        var action = $(this).attr("action");
        var baseUrl = "http://localhost:8090/madrasa/";

        $("#spinnerDiv").show();
        $.ajax({
            url: baseUrl + controller + "/" + action,
            data: {
            },
            type: "GET",
            dataType: "html",
            success: function (data) {
                $('#page-wrapper').html(data);
                $("#spinnerDiv").hide();
            },
            error: function (xhr, status) {
                if (xhr.status == 403) {
                    showForbiddenModal("Sorry, You are not authorized for this action");
                    $("#spinnerDiv").hide();
                    return false;
                }
                console.log("Sorry, there was a problem!");
            },
            complete: function (xhr, status) {
                $("#spinnerDiv").hide();
            }
        });
        e.preventDefault();
    });
})

标签: ajaxgrailsgrails-2.0

解决方案


推荐阅读