WoooHaaaa
WoooHaaaa

Reputation: 20460

How can i generate ajax url from external javascript file in play framework?

I use the "jsAction" tag to generate ajax url in play framework:

var addToFriendURL = #{jsAction @users.addToFriend(':friendId') /}

The code works fine in html template inside a tag,but i found it's invalid in a external javascript file which i include in the html template.

What was happened when i move the code to a external javascript file ?

Upvotes: 0

Views: 413

Answers (1)

Codemwnci
Codemwnci

Reputation: 54924

Once it is moved to javascript file, it becomes statically served content that the Play server does not parse. Therefore, you have a few options

  1. Move your JS into your View directory and create a controller to render the full JS, which can then use the groovy code and tags to do what you need
  2. Keep the dynamic parts of your javascript inside your view, and leave the rest in external files

Personally I would go with option 2, but it may depend on your requirements.

Upvotes: 1

Related Questions