【问题标题】:how to get thymeleaf variable from public source file如何从公共源文件中获取 thymeleaf 变量
【发布时间】:2019-10-24 04:33:52
【问题描述】:

我正在努力学习 thymeleaf,我被这个问题困住了,我无法解决它。

在 javascript 中,如果我想提取 thymeleaf 变量,我只需要这样做

<script th:inline="javascript">
...code
 $.ajax({
                        type: 'POST',
                        url: '/doctors/en/resetPassword?t='+/*[[${token}]]*/,

但是如果我在外部 javascript 文件中有代码怎么办?我不知道是否可以将百里香 xlmns 添加到 .js 文件中,

如果我将 /*[[${token}]]*/ 添加到另一个 java 脚本文件,它将被注释。

那我该怎么办?

请注意,我需要提取来自 ajax 的响应,而不是用于执行 ajax 请求

【问题讨论】:

    标签: java html spring-mvc thymeleaf


    【解决方案1】:

    您可以将 thymeleaf 变量传递给函数:

    <script th:inline="javascript">
    
        /*<![CDATA[*/
    
        getVariable([[${token}]]);
    
        /*]]>*/
    
    </script>
    

    【讨论】:

    • 我不想使用th:inline
    • 要在 javascript 中使用 thymeleaf 变量,您应该使用 th:inline
    猜你喜欢
    • 1970-01-01
    • 2021-08-27
    • 1970-01-01
    • 2018-08-27
    • 2019-10-13
    • 2021-05-28
    • 2019-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多