如何从jquery访问操作控制器值
我是新的TijQuery。有人告诉我如何从jquery访问动作控制器的值吗 我有以下代码在视图中如何从jquery访问操作控制器值,jquery,ruby-on-rails,Jquery,Ruby On Rails,我是新的TijQuery。有人告诉我如何从jquery访问动作控制器的值吗 我有以下代码在视图中 <% @user_rep.each do |result| %> <%= link_to result.time,{:action =>'download_log'}, :id => 'l123'%></td> <% end %> 我在下载日志操作中进行了编码 def download_log IO.foreach "#{RAILS_RO
<% @user_rep.each do |result| %>
<%= link_to result.time,{:action =>'download_log'}, :id => 'l123'%></td>
<% end %>
我在下载日志操作中进行了编码
def download_log
IO.foreach "#{RAILS_ROOT}/public/#{filename}" do |line|
@file_content << line
@file_content << '<br/>'
end
end
def下载日志
IO.foreach“#{RAILS_ROOT}/public/#{filename}”do|行|
@文件内容您可以这样做:
$(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 () {
}
});
});
});
此处的Ajax jQuery文档:如果您希望控制器操作在单击后立即完成,并且希望在jQuery中完成,则必须使用jQuery-Ajax。如果我的答案解决了您的问题,请将其标记为答案,如果没有,请在问题中提供更多详细信息。非常感谢。
$(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 () {
}
});
});
});