Grails的资源插件和AJAX加载的JavaScript [英] Grails Resources Plugin and AJAX loaded javascript

查看:203
本文介绍了Grails的资源插件和AJAX加载的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了资源不同的是异步加载JavaScript的插件在一个Grails 1.3.7应用程序,一切工作正常。

I added the resources plug-in in a grails 1.3.7 application and everything works fine except javascript that is loaded asynchronously.

所以,如果我有一个包含模板的

So if I have a template that contains a

<r:script>
    // javascript here
</r:script>

和通过AJAX的JS code不执行加载它,我得到这个错误:

and load it via ajax the js code does not execute, and I get this error:

您好像缺少了一些调用R:layoutResources标签

It looks like you are missing some calls to the r:layoutResources tag

这是有意义的,因为在网页已经被渲染,并且没有△:layoutResources处理新添加的R:脚本的js code

which makes sense because the page has already been rendered and there is no r:layoutResources to handle the newly added r:script js code.

我发现的唯一的解决方法就是添加 渲染r.layoutResources(配置:推迟) 实际渲染(模板:...)在异步呈现内容的控制器操作。

The only workaround I've found is to add render r.layoutResources(disposition:"defer") after the actual render(template:...) in the controller actions that render content asynchronously.

有没有其他更明确的解决方案?

Is there any other more clear solution?

推荐答案

一个更好的办法是有一个专门的布局你的AJAX响应:

A better approach would be to have a dedicated layout for your AJAX responses:

<g:layoutBody/>
<r:layoutResources disposition="defer"/>

如果您使用的是Grails的2.0,您可以指定在渲染方法布局(渲染模板:......布局:阿贾克斯)。否则,按照惯例使用的布局。

If you're using Grails 2.0, you can specify the layout in the render method (render template: "...", layout: "ajax"). Otherwise, use layout by convention.

这篇关于Grails的资源插件和AJAX加载的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆