[英]How to load a partial inside of a partial?
I'm trying to fire an AJAX request when my page loads. 我正在尝试在页面加载时触发AJAX请求。 I'm guessing this would be best from my controller.
我猜这将是最好的从我的控制器。
First I open a new page.. 首先,我打开一个新页面。
def text_tabs_nav
end
This page has the ability to load by AJAX two different partials. 该页面可以通过AJAX加载两个不同的部分。 I want to load one of them on default.
我想默认加载其中之一。
So I thought maybe this .. 所以我想也许是这个..
def text_tabs_nav
respond_to do |format|
format.html
format.js
end
end
And in my text_tabs_nav.js I wrote this : 在我的text_tabs_nav.js中,我这样写:
== $("#content").html("#{ escape_javascript(render :partial => 'about_us') }");
But the javascript didn't load..I use that same javascript to load things after a page has been loaded, and it works fine. 但是JavaScript没有加载。.我在页面加载后也使用了相同的JavaScript来加载内容,并且效果很好。
Anyone have any idea how I could load a partial ( text_tabs_nav ), with a default AJAX partial loaded within ( about_us ) ? 有谁知道如何加载部分(text_tabs_nav),并在(about_us)中加载默认的AJAX部分?
Thanks! 谢谢!
It isn't being parsed because it's in a vanilla js
file. 由于它位于普通
js
文件中,因此未进行解析。 What you want is 你想要的是
text_tabs_nav.js.erb
Well in a glorious blaze of defeat, I ditched the controller, an added a regular call in my view. 在一次光荣的失败大战中,我抛弃了控制器,在我看来,这是一个常规的电话。
:javascript
$("#content").html("#{ escape_javascript(render :partial => 'about_us') }");
Problem solved. 问题解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.