Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从jquery访问操作控制器值_Jquery_Ruby On Rails - Fatal编程技术网

如何从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

我是新的TijQuery。有人告诉我如何从jquery访问动作控制器的值吗

我有以下代码在视图中

<% @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 () {
            }
        });
   });
});