简体   繁体   中英

Buttons don't make Ajax request but reload page Rails

I am very new with ajax with rails so here is the problem. I have method in controller :multi =>

respond_to do |format|
  format.js
end

The view for metod

<ul id="actions">
    <%= @game.user.actions %>
</ul>

<%= button_link_to "call", drid(:anchor => "opponents", :action => :call, :remote => true), :class => 'button' %>
<%= button_link_to "check", drid(:anchor => "opponents", :action => :check, :remote => true), :class => 'button' %>

@game.user.actions are in the database.

Here is ajax template

$("#actions").append("<%= escape_javascript @game.user.actions %>");
$("#new_action")[0].reset();

Problem is next: when I click on the buttons they add a new events to the list of actions (eg ["call", "call", "call", "call", "check", "call", "call", "check", "check", "check", "call", "call"]), but the page is still reloading without any asynchronus request.

Please help as you can! any answers would be helpful!

call e.preventDefault(); in the JS click-handler for button

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM