[英]Rails/Ajax/ jQuery: Pass multiple params from jquery to Rails controller
[英]Get params from controller using JQUERY RAILS
请帮助我,我是 Rails 上的新手,jquery 在我看来,我尝试从 html 上的数组#mychannels id 元素中获取所有值。
JS AJAX
$(document).ready(function() {
$('#mychannels').change(function () {
$.ajax({
type: "GET",
contentType: "dados/json",
url: "/suporte/chamados?empresa_id=91194",
success: function(data){
alert(data);
}
});
});
});
Controller
def get_data
@company = Company.find(params[:company_id])
@servers = Server.find(:all, :conditions => ["company_id = ? AND action != 3", @company.id])
@channels_list = Channels.where("channel = 't' and company_id = 91194")
我的观点
<%= select_tag "mychannels",options_for_select(@channels_list.map { |e|
[e.name+" - "+e.server.name, e.id]}) %>
我正在尝试读取来自 controller 的数据,并将其显示在视图的 select_tag 中。
你能帮我写代码吗
您需要更新您的 controller 操作,添加渲染方法并添加您希望在 jQuery 成功回调中获得的值。
Controller
def get_data
@company = Company.find(params[:company_id])
@servers = Server.find(:all, :conditions => ["company_id = ? AND action != 3", @company.id])
@channels_list = Channels.where("channel = 't' and company_id = 91194")
render json: { company: @company.to_json, servers: @servers.to_json, channels_list: @channels_list.to_json }
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.