How to get spring mvc controller model key value inside javascript?

前端 未结 3 2040
忘了有多久
忘了有多久 2021-01-12 03:12

I am using a spring mvc controller. Inside controller i am putting some value lets say string inside model. Now i would like to retrive that value or lets just say print tha

3条回答
  •  时光说笑
    2021-01-12 04:08

    Use this:

    var movie_name = "${movie}";
    

    instead of:

    var movie_name = ${movie};
    

    When using ${movie}, the value gets placed on the page without quotes. Since I'm guessing it's a string, Javascript requires strings be surrounded by quotes.

    If you checked your browser's console, you probably would've seen an error like Unexpected identifier or ___ is not defined.

提交回复
热议问题