【发布时间】:2018-07-31 04:28:38
【问题描述】:
我在 Thymeleaf 模板中有这段代码。
<div class="alert_counter" th:classappend="${numDeviceEventsWithAlarm>0} ? show_info">
<span th:text="${numDeviceEventsWithAlarm}">${numDeviceEventsWithAlarm}</span>
</div>
是否可以使用 Ajax 而没有 F5 刷新值 numDeviceEventsWithAlarm ??
【问题讨论】:
-
Thymeleaf 在服务器端呈现您的 HTML 页面,并且在生成内容后没有任何作用。如果你想用 Ajax 来更新网页上的东西,你可以用 Javascript / jQuery 来完成。
-
正如@KedarJoshi 所述以及thymeleaf homepage 中提到的:“Thymeleaf 是一个现代的服务器端 Java 模板引擎,适用于网络和独立环境。” 。所以答案是否定的,您不能更改
${numDeviceEventsWithAlarm}变量,而是给封闭的span一个 ID,稍后使用纯 JS 或您选择的 JS 库更改 span 的内容。
标签: javascript jquery ajax spring-boot thymeleaf