How do you access a model attribute in jquery?

前端 未结 2 1014
挽巷
挽巷 2021-02-02 18:11

I\'m adding an object to my ModelAndView in spring and forwarding to my jsp view. I need to access that object in my jquery. Is this possible without first puttin

相关标签:
2条回答
  • 2021-02-02 18:42
    <script type="text/javascript">
       var modelAttributeValue = '${modelAttribute}';
    </script>
    

    This will resolve the model attribute added by model.addAttribute("modelAttribute", value)

    0 讨论(0)
  • 2021-02-02 18:52

    probably, you can save the model attribute in a hidden field and access it onload as below.

    $(document).ready(function(){
      var modelAttr = $("#modelAttr").val();
      alert(modelAttr);
    }
    
    input type="hidden" id="modelAttr" name="modelAttr" value="${modelAttribute}"/>
    

    Add c:out around the ${modelAttribute} in the jsp.

    0 讨论(0)
提交回复
热议问题