2012-12-12 26 views
0

我是新的ti jquery。有人告訴我如何從jQuery的訪問動作控制器的價值,鑑於如何從jquery訪問操作控制器的值

我有以下代碼...

<% @user_rep.each do |result| %> 
<%= link_to result.time,{:action =>'download_log'}, :id => 'l123'%></td> 
<% end %> 

我JAVE寫在下面的jQuery代碼...

jQuery(document).ready(function(){ 
    jQuery("#l123").click(function() { 
    jQuery("#file").show("slow");  // Showing some div 
    ####What to write here 
    }); 
}); 

而且我編碼在download_log行動

def download_log 
IO.foreach "#{RAILS_ROOT}/public/#{filename}" do |line| 
        @file_content << line 
        @file_content << '<br/>' 
      end 
end 

任何機構告訴我..當我點擊'l123'噸如果控制器操作「download_log」被自動調用,則會顯示一個div?如果可能的話,我怎樣才能在jquery中訪問download_log的值「@file_content」。請幫幫我。

+0

如果你想盡快你點擊完成控制器動作,你想,要成爲在jQuery中完成,你必須使用jQuery-ajax。 – VenkatK

+0

如果我的答案解決了您的問題,請將其標記爲答案,如果沒有在您的問題中提供更多詳細信息。謝謝。 – Gabriel

回答

2

你可以像這樣的東西去:

$(document).ready(function(){ 
    $("#l123").click(function() { 
     $.ajax({ 
      url: urlOfControllerAndAction, 
      type: "get", 
      success: function (response, textStatus, jqXHR) { 
       $("#file").html(response); 
       $("#file").show("slow") 
      }, 
      error: function (jqXHR, textStatus, errorThrown) { 
      }, 
      // callback handler that will be called on completion 
      // which means, either on success or error 
      complete: function() { 
      } 
     }); 
    }); 
}); 

阿賈克斯jQuery的文檔在這裏:http://api.jquery.com/jQuery.ajax/

相關問題