You cannot execute a function while the other executes in JS, being mono-threaded: you can do things before and after , though - are you looking for a way to set a message / counter to be displayed while waiting? Check beforeSend in $.ajax() call:
$.ajax({ type: "POST", url: "mail.php", data: {name: name.val(), email: email.val(), phone: phone.val(), subject: subject.val(), message: message.val()} beforeSend : function(){
source share