![](/img/trans.png)
[英]Spring thymeleaf send javascript dialog message to controller
[英]How to send parametr to Controller properly? (Thymeleaf + Javascript)
我是 Thymeleaf 的初学者。 我所知道的是“Thymeleaf 不是 Javascript,它是在服务器上呈现的”这一事实。 我一直在犯错误,因为我通常尝试像 JavaScript 一样使用 Thymeleaf。
HTML
<form th:action="@{/user/sqlCode}" method="post">
<button id="newDatabase"></button>
</form>
<textarea id="generatedSql" readonly></textarea>
控制器
@PostMapping(path = { "/user/sqlCode" })
public String createSchema(@RequestParam(???) String tmp) {
String finallyMyValue = tmp;
// STOP I want to have data from generatedSql in this moment (finallyMyValue)
// ...
}
@ 使命 @
1.点击按钮(id:newDatabase)
2.从textarea中获取数据(id:generatedSql)
3. 将带有该数据的值发送给控制器
4. 快乐:)
@ 使命 @
我尝试了很多东西,但只使用 Javascript。 场景总是相同的,JavaScript 完全在 Thymeleaf 之前执行,最后我无法正确读取该数据......我尝试了这种场景:
name
中name
发送到控制器。我认为您应该尝试在 Ajax 中使用 Javascript:
<div>
<button type="button" onclick="submitData()">Change Content</button>
</div>
function submitData() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
xhttp.open("post", "$URL", true);
xhttp.send();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.