我有以下几点:
<%= link_to my_path, method: :delete, confirm: 'Delete?', class: 'link-delete', 'data-message' => 'Are you sure?', 'data-severity' => 'danger', :remote => true do %> <i class="icon-trash"></i> <% end %>
这会弹出一个Bootstrap Modal进行确认,我想挂接到一个ajax调用上,以便我可以显示微调器或某种文本。
我知道如果我在link_to中不使用’:remote => true’的话,我可以使用简洁的javascript来监听click事件。
jQuery -> $('.link-delete').live 'click', (event) -> $('.link-delete').html("Loading...") #THE MSG OR ANIMATION I WANT TO DISPLAY $.get(this.href, null, null, 'script') false
但不确定使用’:remote => true’时如何结合两者
有什么建议?
谢谢您的帮助
您可以像这样绑定到ajax调用:
<%= link_to my_path, method: :delete, confirm: 'Delete?', class: 'link-delete', 'data-message' => 'Are you sure?', 'data-severity' => 'danger', :remote => true do %> <i class="icon-trash"></i> <% end %> $('.link-delete').bind('ajax:beforeSend', function() { $('#mySpinner').show(); }); $('.link-delete').bind('ajax:complete', function() { $('#mySpinner').hide(); });