I heard people said php codes will be
finished loaded then only will start
loading javascript.
This is absolutely true, your server scripts will be run first.
The reason it doesn't alert()
anything is because $username
does not even exist yet...
Once the PHP script runs it is done, unless you call more from AJAX.