if you would use ajax, use it for the whole process. So, no such problems at all. Get response and show it to user.
But as you stated yourself as a newbie, I'd strongly advise you to do it straight and simple way, just to learn how the things are.
As a general rule, a redirect always preferred after POST method request. In some cases one can omit this, but for the login form you would use a session anyway. So, you can start a session, write an error information there and then do Location:
redirect.
After it, check session for the errors, and then notify user using any method you wish: a div, or a popup or anything.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…