[英]Buttons don't make Ajax request but reload page Rails
I am very new with ajax with rails so here is the problem. 我对带有Rails的Ajax非常陌生,所以这里就是问题所在。 I have method in controller :multi => 我在控制器中有方法: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. @game.user.actions
在数据库中。
Here is ajax template 这是ajax模板
$("#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();
调用e.preventDefault();
in the JS click-handler for button 在JS点击处理按钮中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.