Reputation: 5749
I use thymeleaf and spring. I try to do inline javascript.
<script th:inline="javascript">
$("#genericTable").bootstrapTable({
url: /*[[${url}]]*/ 'generic',
...
});
On the server side I do
model.addAttribute("url", "/rest/vehicles");
I get
url: "\/rest\/vehicles",
Why some caracters are added to the string?
Edit
with
url: /*[[@{${url}}]]*/ 'generic',
first / is like removed, so it's invalid to call...
Upvotes: 4
Views: 4599
Reputation: 51
I know the question is a little old but the answer don't correct the problem, or the same I faced. To remove escaping I suggest to write code like this (double quotes are here only for javascript purpose) :
<script type="text/javascript" th:inline="javascript">
/*<![CDATA[*/
$("#genericTable").bootstrapTable({
url: "[(@{ ${url} })]",
...
});
/*]]>*/
</script>
Upvotes: 0
Reputation: 2252
[(...)]
should help
Example with problem I am facing:
$.getJSON('[[@{/management/users/search/unit/}]]' + value, function(data) {
Is transformed to:
$.getJSON('"\/management\/users\/search\/unit\/"' + value, function(data) {
Using [(...)]
:
$.getJSON('[(@{/management/users/search/unit/})]' + value, function(data) {
Is transformed to:
$.getJSON('/management/users/search/unit/' + value, function(data) {
From Thymeleaf 3.0 docs
Note that, while [[...]] corresponds to th:text (i.e. result will be HTML-escaped), [(...)] corresponds to th:utext and will not perform any HTML-escaping.
Upvotes: 9
Reputation: 7095
You can try something like this:
<script type="text/javascript" th:inline="javascript">
/*<![CDATA[*/
$("#genericTable").bootstrapTable({
url: /*[[${url}]]*/ 'generic',
...
});
/*]]>*/
</script>
Upvotes: 3