Again, AJAX is async. So the showMsg function will be called only after success response from the server..
stackoverflow.com