I have a String variable, containing XML. I added it to my model with modelAndView.addObject(...). Now, how can I access this object in Javascript ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Let's say that in your controller you did something like
modelAndView.addObject("someValue", someValue)
.
In your JSP, you can do this :
<script type="text/javascript">
var someValue = "${someValue}";
</script>
And then you can use this variable in your JS.
回答2:
Assuming you want to access Model attribute
Using <c:set>
like
<c:set var="myData" value="${myObject.data}" />
and then you can use this var in js using ${myData}
.
For example in jQuery selector
<script>
$("#${myData}").val('foo');
</script>