Jquery 如何通过ajax从用于填充放置淹没列表的数组中传递参数?

Jquery 如何通过ajax从用于填充放置淹没列表的数组中传递参数?,jquery,ruby-on-rails,ajax,parameters,Jquery,Ruby On Rails,Ajax,Parameters,我有以下看法: index.html.js <h5>Select your state:</h5> <%= select_tag "state", options_for_select(@states.collect{|x| x[0]}), :onchange => '$.get("/home/populate_options")' %> 如何通过ajax将包含所选状态值的参数(如果选择了Alaska,“AK”应发送到控制器操作)传递给控制器操作 在发

我有以下看法:

index.html.js
<h5>Select your state:</h5>
<%= select_tag "state", options_for_select(@states.collect{|x| x[0]}), :onchange => '$.get("/home/populate_options")' %>
如何通过ajax将包含所选状态值的参数(如果选择了Alaska,“AK”应发送到控制器操作)传递给控制器操作

在发送
$.get(“/home/populate\u options”)
之前,我是否必须在javascript中手动构建url,使其看起来更像
$.get(“/home/populate\u options/AK”)
?也许我需要改变我使用助手的方式,这样我就可以实际使用“rails-like”助手,只需使用符号发送参数:state=>“AK”?

试试这个:

当你有这样的
@states=[['AK','AK'],['AL','AL']]
时。您不需要使用
收集
,只要
@状态
就足够了

要在params
onchange
中发送值,可以执行以下操作:

  <%= select_tag "state", options_for_select(@states), :onchange => '$.get("/home/populate_options?state="+$(this).val())' %>
“$.get(“/home/populate_options?state=“+$(this.val())””%%>

但是在您的问题中,不清楚您究竟在哪里从
ajax

填充数据完美!到那时为止,我还没有进行重构,
collect
的东西肯定是不必要的。谢谢,state=“+$(this).val()正是我所需要的。
  <%= select_tag "state", options_for_select(@states), :onchange => '$.get("/home/populate_options?state="+$(this).val())' %>