Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中使用Thymeleaf显示消息_Javascript_Spring Mvc_Thymeleaf - Fatal编程技术网

在javascript中使用Thymeleaf显示消息

在javascript中使用Thymeleaf显示消息,javascript,spring-mvc,thymeleaf,Javascript,Spring Mvc,Thymeleaf,我正在使用thymeleaf和Spring3MVC。 当我尝试执行Ajax POST请求时,我不明白如何在html页面上显示来自控制器的响应消息: 下面是一段代码片段: $.ajax({ type: "POST", url: "/settings", data: "request=" + request, success: function (response) { $('#msg').replaceWith('<div id="msg" t

我正在使用thymeleaf和Spring3MVC。 当我尝试执行Ajax POST请求时,我不明白如何在html页面上显示来自控制器的响应消息:

下面是一段代码片段:

$.ajax({
    type: "POST",
    url: "/settings",
    data: "request=" + request,
    success: function (response) {
        $('#msg').replaceWith('<div id="msg" th:text="response"></div>');
    },
});
$.ajax({
类型:“POST”,
url:“/settings”,
数据:“请求=”+请求,
成功:功能(响应){
$('#msg')。替换为('');
},
});
“响应”是来自控制器的i18n消息。现在,我想在使用thymeleaf(th:text=“response”)时显示此消息。当然,这段代码不起作用,因为它认为响应变量是一个普通字符串

问题是如何使用thymeleaf显示i18n响应消息。或者可能还有其他一些方法可以通过js在html页面上显示i18n消息(不使用jsp)?

Thymeleaf属性(如th:text)将仅在服务器上解析和替换。由于此ajax响应是在浏览器上处理的,因此不会处理th:text。如果“设置”已经是一个Thymeleaf解析页面,那么它可能已经是i18n了,您可以简单地执行以下操作:

$('#msg').html(response);

但是,如果您真的在寻找SyeleleAF标签的客户端JavaScript处理,请考虑./P>