[英]Getting html and javascript to load in correct order in rails
我的菜单中有一个link_to:remote ajax调用,单击该链接可动态呈现每个页面的内容。 一切都应按其应有的方式被调用和替换,但是当我第二次单击菜单链接时,D3和vticker仅绑定到它们各自的div。 这使我相信html / js的加载顺序不正确。 因此,当它第一次加载时,没有div可以绑定到它。
此外,在替换的内容内,我有一个内部ajax查询,它根据单击的d3工具提示来更新新闻行情自动收录机,替换内容后,行情自动收录机ajax查询不再起作用,我得到了:
GET http://localhost:3000/render_bubble_partial?data=The+Environment 404 (Not Found)
这很奇怪,因为它之前已经起作用,并且我已经设置了路由:
bubbles_render_bubble_partial GET /bubbles/render_bubble_partial(.:format) bubbles#render_bubble_partial
bubbles_render_poll_partial GET /bubbles/render_poll_partial(.:format) bubbles#render_poll_partial
bubbles_render_bubble_content GET /bubbles/render_bubble_content(.:format) bubbles#render_bubble_content
菜单中的li部分:
<li id='panel-3'><%= link_to image_tag('keyBubble.png'), bubbles_render_bubble_content_path, :remote => true %></li>
我渲染的部分内容:
<div class="col span_5_of_7">
<section id="infographic">
<div id ="infographicContent">
<input id="slider" style="position:inherit;top:4px;" type="range" min="0" max="62" value="0"> </input>
<div id="tooltip">
</div>
<%= javascript_include_tag "http://d3js.org/d3.v3.min.js" %>
<%= javascript_include_tag "bubbles", "vticker" %>
<script>
$('.col.span_5_of_7').click(function(){
var text = $("#tooltip b").text();
if(text == ""){text = null}
var params = {data:text};
console.log(params)
$.ajax({
url: "render_bubble_partial",
data: params,
success: function(result) {
console.log("finished ajax callback");
}
});
});
</script>
</div>
</section>
</div>
<div class="col span_1_of_7">
<section id="feed">
<div id ="infoFeed">
<ul style="font: 10px sans-serif;text-align: justify;">
<% bubble_query(nil) %>
<% @bubble_story.each do |story| %>
<li style="border-style:solid;border-top:thick double #000;">
<p><h4 style="text-align:left;"><%= link_to story.title, story.url, :target => "_blank" %>
</h4> <%= story.description %> <h7><br /><br /><%= story.source %><br /><%= story.date.to_date %><%= story.issue %></h7></p>
</li>
<% end %>
</ul>
</div>
</section>
<script> $(function() { $('#infoFeed').vTicker();});</script>
</div>
我不确定该如何解决...有人可以提供一些建议吗?
您是否正在调用ajax从本身由ajax更新的部分中重新加载部分? 如果是这样,请尝试将其移出。 您可以尝试将JavaScript移至应用程序布局或application.js文件。
但是在部分布局和应用程序布局之间移动javascript_include_tags,我能够使其正确加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.