2013-10-27 37 views
4

我無法弄清楚如何正確獲取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> 

我不知道如何獲得這個序列正確的,任何人都可以協助嗎?

+1

'jQuery.html()'會去掉腳本標籤。可以使用'jQuery.load()'用ajax加載div ...它保留並允許腳本執行。否則,爲什麼你需要使用javacript來設置html?查看jQuery API文檔 – charlietfl

+0

您的瀏覽器控制檯說什麼?當你檢查AJAX響應時,它的格式是否正確? – juanpastas

+0

你收到任何錯誤,你的請求看起來像ajax調用後? –

回答

3

在您要加載部分的主頁面中加入您的JavaScript。

+0

我的JavaScript有很多邏輯與正在呈現的對象有關。有其他解決這個問題的方法嗎? – marimaf

+0

根本不幹,特別是對於表格代碼,如ckeditor。把腳本標籤放在部分形式中會很好。 – ahnbizcad