JavaScript库中的Grails应用程序上下文 [英] Grails application context in javascript library
本文介绍了JavaScript库中的Grails应用程序上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以访问
grails.app.context
来自一个JavaScript库吗? - 也就是说,没有在GSP文件中插入JavaScript。
我有一些依赖于上下文的som javascripts,为什么我需要能够从javascript访问它。 / p>
我将JavaScript包含在我的gsp-files中:
< ; r:require modules =myModule/>
解决方案
您可以将它作为全局JS变量传递给Javascript,把它放在< head>
标记中:
< g:的javascript>
window.appContext ='$ {request.contextPath}';
< / g:javascript>
并在任何地方使用普通的javascript,比如:
$。ajax({
url:appContext +'/ hello / world'
})
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'
})
这篇关于JavaScript库中的Grails应用程序上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文