Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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
Javascript 如何在链接路径中获取变量_Javascript_Jquery_Ruby On Rails_Ajax - Fatal编程技术网

Javascript 如何在链接路径中获取变量

Javascript 如何在链接路径中获取变量,javascript,jquery,ruby-on-rails,ajax,Javascript,Jquery,Ruby On Rails,Ajax,我试图使用以下链接_中的变量调用: <%= link_to '<button type = "button">Players</button>' .html_safe, live_players_path(:Team => @tmf) %> 总之,我从select下拉列表中选择了一个团队,它触发了ajax,ajax在控制器中设置@tmf变量,但是当单击链接时,变量(@tmf)为nil。如何使变量保持不变,以便以后使用?这将在服务器上呈现,并在用

我试图使用以下链接_中的变量调用:

<%= link_to '<button type = "button">Players</button>'
    .html_safe, live_players_path(:Team => @tmf) %>

总之,我从select下拉列表中选择了一个团队,它触发了ajax,ajax在控制器中设置@tmf变量,但是当单击链接时,变量(@tmf)为nil。如何使变量保持不变,以便以后使用?

这将在服务器上呈现,并在用户的第一个请求期间发送到客户端:

<%= link_to '<button type = "button">Players</button>'
    .html_safe, live_players_path(:Team => @tmf) %>

顺便说一句,对于其他看到我刚刚用过的这篇文章的人:

$('selector').attr('href','url')


选择器是元素,url是请求的信息。

ok,让我看看我是否理解这一点。我使用一个按钮来代替链接,当点击按钮时,它将使用url
url:http://localhost:3000/live_players.json“+”?TmFilter=“+Tm+”&Selected=“+SelectTm,
成功后,将按钮的href设置为适当的链接,以获取我的视图以刷新表格?太棒了,一旦我明白了该怎么做,我就把你的建议变成了常规代码,瞧!非常感谢,很高兴我能帮忙!
$(document).ready(function(){
    $('#FilterTm').change(function(){
        Tm = $('#FilterTm').val();
        SelectTm = true;
        $.ajax (
            {
                url: "http://localhost:3000/live_players.json' +
                    '?TmFilter="+Tm+"&Selected="+SelectTm,
                type: "get",
                dataType: "json",
                cache: true,
                success: function(data) {
                    alert("Loading Players....");
                },
                error: function(error) 
                {
                    alert("Failed " + console.log(error) + " " + error);
                }
            });
    });
});
<%= link_to '<button type = "button">Players</button>'
    .html_safe, live_players_path(:Team => @tmf) %>
<a id="playerBtn"><button type="button">Players</button></a>
var playerBtn = $("#playerBtn");    

...

success: function(data) {
  alert("Loading Players....");
  playerBtn.href= "url/?Team=" + data.tmf;
},