通过 ajax 渲染的部分内容不包含 javascript,而它应该包含
我有一个通过 ajax 渲染的部分,结果用于替换 div 的内容。该部分正确渲染,但是当我检查元素时,javascript 标记及其 javascript 未在浏览器中渲染。部分类似于以下内容
<style>
/* some styles */
</style>
<script type="text/javascript">
alert("did it work");
</script>
<% @array.each do |el| %>
<!--make table w/ array -->
<% end %>
当我检查元素时,除了 javascript 之外,所有内容都在那里。我的 Ajax.Updater 选项上有 evalJS: true (我正在使用原型,但我认为这没有任何区别)。奇怪的是,当我将以下内容放入操作中时,我可以在控制台中看到带有 js 的渲染模板
test = render :partial => "my_partial.html.erb"
puts test
test
任何帮助将不胜感激。
I have a partial that is being rendered via ajax and the result used to replace a div's contents. This partial is rendering correctly but when I inspect the element the javascript tag and it's javascript is not rendered in the browser. The partial is similar to the following
<style>
/* some styles */
</style>
<script type="text/javascript">
alert("did it work");
</script>
<% @array.each do |el| %>
<!--make table w/ array -->
<% end %>
When i inspect the element everything is there but the javascript. and i have evalJS: true on my Ajax.Updater options (i'm using prototype but i don't think that makes any difference). The odd thing is that when i put the following in the action i can see the rendered template in the console w/ the js
test = render :partial => "my_partial.html.erb"
puts test
test
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看此处: http://api.prototypejs.org/ajax/Ajax/Updater/< /a> 您会注意到正确的选项名称是 evalScripts(但请阅读它的用法,因为它有一些限制)。
If you look here: http://api.prototypejs.org/ajax/Ajax/Updater/ you will notice that the correct option name is evalScripts (but read about its use, because it has some limitations).