How to defer a default action?

in jquery, I need to defer the behavior of anchors by default, so that at the same time, the ajax send request can complete itself.

preventDefault or returning false in the .click event will not be because I still need to go to these pages. window.location = href obviously does not work, because some anchors do not have the href attribute, but use javascript instead. I do not control these pages.

+3
source share
2 answers

You just use the 'success' callback in ajax for jQuery itself

 $.ajax({
   type: "POST",
   url: "some.php",
   data: "name=John&location=Boston",
   success: function(msg){
     // do what you need to here

     return true;
   }
 });

He will then wait for Ajax to complete before proceeding to a successful callback.

+1
source

href, , . - click href , callback.

0

Source: https://habr.com/ru/post/1718616/


All Articles