in jquery, i need to delay the default behavior of anchors, so that in the meantime, ajax post request can complete itself.
preventDefault or returning false in .click event wont do, as I still need to navigate to those pages. window.location = href obviously fails because some anchors do not have href attribute instead uses javascript. I do not control these pages.
You just use the 'success' callback within the ajax function 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;
}
});
Then it will wait until the Ajax has completed before moving on to the success callback
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With