How get more than one data from #authentication.getPrincipal(). in Javascript

Viewed 74

I get information about user and send it with AJAX to server.

this work fine:

<script>
       /*<![CDATA[*/  
            data.orderId = [[${theOrder.id}]]; 
            data.UserId = [[${#authentication.getPrincipal().getId()}]]; /*]]>*/
</script>

When I add One more:

/*<![CDATA[*/ data.fromUserName = [[${#authentication.getPrincipal().getName()}]]; /*]]>*/

it broke the code and throw error in browser console: Uncaught SyntaxError: Unexpected identifier. I check .getName() on thymeleaf and it work.

1 Answers

I don't know why it don't work with one than one variable. But in Thymeleaf 3 this constration work with many varibles:

<script th:inline="javascript">
    var username = [[${session.user.name}]];
</script>
Related