我無法弄清楚如何正確獲取HTML/JavaScript加載。因此highcharts沒有正確的div加載來運行時呈現圖表。JavaScript不執行AJAX後部分呈現在軌道上
我有偏的菜單:
<ul class='kwicks kwicks-vertical'>
<li id='panel-1'><%= link_to_unless_current image_tag('keyIssues.png'), load_key_issues_path, remote: true %></li>
<li id='panel-2'><%= link_to_unless_current image_tag('pollVsLeader.png'), load_polls_path, remote: true %></li>
</ul>
那個叫時運行的方法home_controller.rb:
def load_key_issues
respond_to do |format|
format.js
format.html { render :action => "refresh", :notice => 'Update SUCCESSFUL!' }
end
end
那然後運行load_key_issues.js.erb:
$("#replace").html("<%= j render partial: 'shared/key_issues' %>");
然後在部分呈現這個HTML:
<div class="col span_6_of_7">
<section id="infographic">
<div id ="infographicContent">
<%= javascript_include_tag "highcharts" %>
<%= javascript_include_tag "chart" %>
<div id="chart" style="min-width: 310px; height: 700px; margin: 0 auto"></div>
</div>
</section>
</div>
我不知道如何獲得這個序列正確的,任何人都可以協助嗎?
'jQuery.html()'會去掉腳本標籤。可以使用'jQuery.load()'用ajax加載div ...它保留並允許腳本執行。否則,爲什麼你需要使用javacript來設置html?查看jQuery API文檔 – charlietfl
您的瀏覽器控制檯說什麼?當你檢查AJAX響應時,它的格式是否正確? – juanpastas
你收到任何錯誤,你的請求看起來像ajax調用後? –