进行动态选择时出错。当我改变我的选择时,我的ajax不起作用。出现选择动态更改其他选择导轨
这是视图代码:
<%= select_tag 'cost', options_for_select(Cost.all.map { |c| ["#{c.types}", c.id] }),:id => "cost_select" %>
<script type="text/javascript">
$(document).ready(function(){
$("#cost_select").live('change',function(){
$.ajax({
url: "finances/cost_type",
type: "GET",
data: {'cost=' + $('#cost_select option:selected').value() },
})
});
});
</script>
林我的财务控制,我有这样的:
def cost_type
@places = Place.find_by_cost_id(params[:cost])
respond_with @places
end
我做cost_type.js.erb
文件,我的回答是JS。
我的问题是,当我改变选择标签不活动没有人的行动,如何在我的搜索代码惠特代码我发现此代码工作,但是什么问题?
UPDATE:
我的routes.rb包含:
get "finances/cost_type" => "finances#cost_type"
我解决了我用下面的原题:
$(document).ready(function(){
$("#cost_select").change(function(){
$.ajax({
url: "finances/cost_type",
type: "GET",
data: {cost: $("#cost_select option:selected").val() },
})
});
});
有了这个,我收到了有效响应(我通过萤火虫验证):
$("#cost_select").after("<select id="from_money" name="from_money"><option value="2">Luz</option></select>
");
但是,数据并未出现在我看来。我试图把它放在不同的<div>
,但<select>
不会出现。
我不知道什么是错,请给我提供任何可能的建议。
尝试在您的ajax中使用'data:{cost:$('#cost_select option:selected').value()}'。 –
没有作品,不工作的事件来改变,不会出现什么嗯,我更新惠特routes.rb – overallduka
你是否在你的行动中获得成本的价值? –