Skip to content Skip to sidebar Skip to footer

Spring Mvc : How To Access A Modelandview Xml Object In Javascript ?

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 ?

Solution 1:

Let's say that in your controller you did something like

modelAndView.addObject("someValue", someValue).

In your JSP, you can do this :

<scripttype="text/javascript">var someValue = "${someValue}";
</script>

And then you can use this variable in your JS.

Solution 2:

Assuming you want to access Model attribute Using <c:set> like

<c:setvar="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>

Post a Comment for "Spring Mvc : How To Access A Modelandview Xml Object In Javascript ?"