javascript - Rails link_to ignoring e.preventDefault(); from a jQuery call because method: :get is set -


experimentally i've learned following code:

        <td><%= link_to 'notify', '/w/'+w.id+'/notify', method: :get, :class => "btn btn-success notify-btn" %></td> 

fires regardless of jquery:

  $('.notify-btn').click(function(e){     e.preventdefault();     bootbox.confirm("alert?", function(result){       if(result === true){         return true;       } else {         return false;       }     });   }); 

and it's due method: :get. removed elements of link one-by-one , tried various combinations. if method: :get there, it's going fire.

i can prevent e.stoppropagation, won't follow link at all. if click ok sits on page doing nothing.

if rid of erb , use straight html so:

<a href="/w/53531e8a963e6503c60002b2/notify" class="btn btn-success notify-btn" data-method="get">notify</a> 

and data-method="get" there, same result. if remove data-method, pop alert , prevent following link, won't fire link @ if confirm.

any ideas on i'm doing wrong?

  $('.notify-btn').click(function(e){     e.preventdefault();     e.stoppropagation();     var link = $(this).attr('href')     bootbox.confirm("alert?", function(result){       if(result){         window.location = link;         return true;       } else {         return false;       }     });   }); 

i had use trickery - above works.

oddly required both preventdefault , stoppropagation in end. tried every possible combination.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -