ajax - Appear Select dynamic on change other select Rails -
i have error when making dynamic select. ajax doesn't work when alter select.
this view code:
<%= 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>
im finances controller, have this:
def cost_type @places = place.find_by_cost_id(params[:cost]) respond_with @places end
i create cost_type.js.erb
file, , response in js.
my problem when alter select tag dont active no 1 action, how problem whit code in searchs find code working problem?
update:
my routes.rb contains:
get "finances/cost_type" => "finances#cost_type"
i solved original question following:
$(document).ready(function(){ $("#cost_select").change(function(){ $.ajax({ url: "finances/cost_type", type: "get", data: {cost: $("#cost_select option:selected").val() }, }) }); });
with this, received valid response (which verified via firebug):
$("#cost_select").after("<select id="from_money" name="from_money"><option value="2">luz</option></select> ");
however, info isn't appearing in view. tried putting in different <div>
<select>
won't appear.
i don't know wrong, please provide me possible suggestions.
change javascript to
$(document).ready(function(){ $("#cost_select").live('change',function(){ $.ajax({ url: "/finances/cost_type", type: "get", data: { cost: $('#cost_select').val() } }) }); });
the /
before finances makes sure you're using absolute paths. data
part wrong pointed out in 1 of comments cleaner version.
ruby-on-rails ajax ruby-on-rails-3 jquery ruby-on-rails-3.1
No comments:
Post a Comment