JavaScript 中的 GSP 标签
我在 GSP 的 中有以下内容
<script type="text/javascript>
$("button.remove-item").click(function() {
$.ajax({
url: "${createLink(action: 'remove', controller: 'cart')}",
type: 'POST'
});
});
</script>
请注意,我正在使用 Grails createLink 标签来构造 AJAX 请求将发布到的 URL。当我将此代码移至 checkout.js
并将上面的代码块替换为:
<script type="text/javascript" src="${resource(dir: 'js', file: 'checkout.js')}"></script>
Grails 不再评估 createLink
标记。因此,看起来 块中的 Grails 标记会被评估,但 GSP 包含的 .js 文件中的标记不会被评估 - 有没有办法改变这一点?
I had the following in the <head>
of a GSP
<script type="text/javascript>
$("button.remove-item").click(function() {
$.ajax({
url: "${createLink(action: 'remove', controller: 'cart')}",
type: 'POST'
});
});
</script>
Notice that I'm using the Grails createLink tag to construct the URL that the AJAX request will post to. When I moved this code into checkout.js
and replaced the block of code above with:
<script type="text/javascript" src="${resource(dir: 'js', file: 'checkout.js')}"></script>
the createLink
tag is no longer evaluated by Grails. So it seems that Grails tags within <script>
blocks are evaluated, but tags within .js files included by GSPs are not - is there a way to change this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 GSParse 插件,将 css 和 js 解析为 gsp 文件:
http://nerderg.com/GSParse
http://grails.org/plugin/gsp-arse
Check out the GSParse plugin to have css and js parsed as a gsp file:
http://nerderg.com/GSParse
http://grails.org/plugin/gsp-arse
你是对的,grails 不会评估 .js 文件!但普惠制是!这就是为什么当你设置标签时它起作用了。
我建议您采用不同的方法来获取该链接!当你使用jquery时,我会这样做:
checkout.js:
You are right .js files are not evaluated by grails! but the GSP are! so thats why when u were setting a tag it was working.
I would suggest you to have a differente approach of how to grab that link! as u are using jquery I would do like this:
checkout.js: