取消确认对话框仍然提交链接

时间:2014-06-13 19:27:08

标签: javascript jquery ruby-on-rails jquery-mobile haml

我在提交和正确取消之前尝试进行链接确认。下面是我的代码行:

= button_to 'Complete Disconnect', {:controller => 'disconnects', :action => 'physical_disconnect', :id => d.id }, :data => { :role => 'button', :confirm => 'Are You Sure?' }

我收到对话框,但是当我点击取消时它会提交。我在这个页面上使用jquery mobile。我能做到这一点的好方法吗?

修改

所以我也尝试过:

= link_to 'Complete Disconnect', {:controller => 'disconnects', :action => 'physical_disconnect', :id => d.id }, :class => "disconnect", :onclick => "return confirm('are you sure?')", :data => { :role => "button" }

并使用此javscript:

:javascript
  $('.disconnect').click(function(){
    var url = this.href
    if(confirm("You Sure?")){
      $.ajax({
        type:"POST",
        url: url,
        success: function(){
          console.log("Success")
        },
      });
    }
  });

取消仍然提交请求

0 个答案:

没有答案