I'm very new to thymeleaf. Here i have stuck in passing parameter. Here is my html page.
<tr th:each="result : ${searchResult}">
<td>
<a href="#" th:text="${result.getString('type')} +'|'+ ${result.getString('name')} +'|'+ ${result.getString('revision')}"></a>
</td>
<td>
<a href="#" role="button" class="green" data-toggle="" onclick="dataSearchAjax1('Source','sourceResultDiv')">view</a>
</td>
</tr>
This is my javascript function
function dataSearchAjax1(searchType, resultDiv) {
var typeVar=searchType;
$.ajax({
url : 'dataSearchAjax1',
data: {type:typeVar},
success : function(data) {
$('#'+resultDiv).html(data);
}
});
}
Here i Have to pass result.getString('type') and result.getString('name') instead of 'source' and 'sourceResultdiv'.
I have tried
th:onclick="'javascript:dataSearchAjax1(\'' + ${result.getString('type')},${result.getString('name')} + '\');'"
Also i tried with th:attr="online...tag..Both are not working. Can somebody please help me?
You need to escape the ,
separator also, so the code to perform the function call would be:
th:onclick="'javascript:dataSearchAjax1(\'' + ${result.getString('type')} +'\',\''+ ${result.getString('name')} + '\');'"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With