开发者

Render a partial as a radio button is checked, using ajax

开发者 https://www.devze.com 2023-03-14 06:16 出处:网络
My search field These are my radio buttons <% [ \'categorie\', \'strutture\', \'attivita\', \'servizi\' ].each do |type| %>

My search field

These are my radio buttons

    <% [ 'categorie', 'strutture', 'attivita', 'servizi' ].each do |type| %>
      <%= radio_button_tag 'search_type', type, params[:search_type] == type %>
      <%= type.humanize %>
    <% end %>

i would like to render a partial as soon as one of them is selected.

I think this should be very similar to the ajax call i'm using for the instant search, that is:

this code in application.js

$("#facilities_search input").keyup(function() {
    $.get($("#facilities_search").attr("action"), $("#facilities_search").serial开发者_JAVA百科ize(), null, "script");
    return false;
  });

and this in index.js.erb

$("#facilities").html("<%= escape_javascript(render("facilities")) %>");

Please can you help me? Thanks!


Ok, it was quite easy!

The point was to add this to my application.js

  $("#search_type_categorie, #search_type_attivita, #search_type_servizi, #search_type_strutture").live("change", function() {
    $.get($("#global_search").attr("action"), $("#global_search").serialize(), null, "script");
    return false;
  });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号