javascript - prevent a link from redirecting to another page -
i have link in page, , want prevent link redirect me link in href attribute.
i tried following:
$(function(){ $('#logout-link').click(function(event){ event.preventdefault(); $.ajax({ url : $(this).attr('href'), success : function(data){ $('#login-loader').hide(); location.reload(true); }, error : function(){ $('#error-login').replacewith('<div id="error-login" class="msg fail"><p>une erreur été rencontrée lors du deconnexion!</p></div>'); } }); }); });
but stills redirect me tho other page.
how can prevent link redirecting page ?
try return false;
instead of event.preventdefault();
use after ajax call.
Comments
Post a Comment