Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails application context in javascript library

Tags:

grails

Is it possible to access

grails.app.context

from within a javascript library? --That is, not javascript inserted in a GSP file.

I have som javascripts that are context dependent, why I need to be able to access this from javascript.

I include the javascript in my gsp-files with:

<r:require modules="myModule" />
like image 399
Hoof Avatar asked Feb 20 '23 07:02

Hoof


1 Answers

You can pass it to Javascript as global JS variable, put this inside <head> tag:

<g:javascript>
   window.appContext = '${request.contextPath}';
</g:javascript>

and use it anywhere from plain javascript, like:

$.ajax({
   url: appContext + '/hello/world'
})
like image 101
Igor Artamonov Avatar answered Mar 07 '23 23:03

Igor Artamonov