junaidp
junaidp

Reputation: 11201

Grails : how to access data in javascript from controller

I have some data in My controller which i want to use in Javascript in my gsp file

class MainController {
    def test = {

        def value = 111.10
    }
}

TEST.GSP

<html>
    <head><title>Simple GSP page</title></head>
    <body>
        <script language="JavaScript">
            alert("${value}")
        </script>
    </body>
</html>

Dialog box appears but without any value .. Any Solution ..?

Thanks

Upvotes: 0

Views: 1718

Answers (1)

Chris
Chris

Reputation: 8109

You need to explain grails, that he local variable value should be accessible in the view, by returning a map of all variables, that should be accessible in the view:

class MainController {
    def test = {

        def value = 111.10
        [value: value]
    } 
}

Upvotes: 1

Related Questions