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

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -