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" />
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'
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With