score:0

Accepted answer

Maybe this way?

jsfile:

@scripts = {
        <script type="text/javascript" src="@routes.Application.javascriptRoutes"></script>
        <script type="text/javascript">
        jsRoutes.controllers.Application.messages("admin.venue.1,admin.venue.2,admin.venue.3" ).ajax({
            type: 'GET',
            success: function (data) {
                console.log(data.messages);

        },
            error: function () {
                console.log("error");
            }
        });
        </script>    
    }

Controller:

object Application extends Controller {

  def javascriptRoutes = Action {
    implicit request =>
      import routes.javascript._
      Ok(
        Routes.javascriptRouter("jsRoutes")
          (
            routes.javascript.Application.messages
          )
      ).as("text/javascript")


  }

  def messages(keys : String) = Action {
    implicit request => {
      val messages = keys.split(",").map { key =>
        key -> Messages(key)
      }.toMap

      Ok(Json.obj("status" -> "OK", "messages" -> messages))
    }
  }

}

routes:

# Javascript routes
GET         /javascriptRoutes                 controllers.Application.javascriptRoutes
GET         /messages                       controllers.Application.messages(keys: String)

Related Query

More Query from same tag