How do you access a model attribute in jquery?

前端 未结 2 1016
挽巷
挽巷 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: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.

提交回复
热议问题