So I have a log in form and I created this function for the submit:

Code:
$('#logonform').submit(function() {		
		errortxt="";
		errors=0;
		if ($('#usernamelogin').val() == "") {errors++; errortxt += "<li>Please enter your <strong>Username</strong>.</li>";}
		else if ($('#usernamelogin').val().length < 5) {errors++; errortxt += "<li>Your <strong>Username</strong> must be at least 5 characters long.</li>";}
		if ($('#passwordlogin').val() == "") {errors++; errortxt += "<li>Please enter your <strong>Password</strong>.</li>";}
		
		var usernamelogin = $('#usernamelogin').val();
		var passlogin = hex_md5($('#passwordlogin').val());
		var dataString = "userdata="+usernamelogin+"&amp;"+"pwdata="+passlogin;
		
		if (errors != 0) {
			$("#loginerr .formee-msg-error ul").html(errortxt); 
			$("#loginerr").css('display','block'); 
			return false;
		} else {
			$("#logstatus").html('<img align="absmiddle" src="images/loader.gif" /> Hmmm..');
			$.post('logincheck.php',{userdata:usernamelogin, pwdata:passlogin}, function (data) {
				if (data == 'NO') {
					errortxt += "<li>Your <strong>Username</strong> or <strong>Password</strong> are incorrect.</li>";
					$('#logstatus').html("");
					$("#loginerr .formee-msg-error ul").html(errortxt); 
					$("#loginerr").css('display','block'); 
					return false;
				} else if (data == 'OK') {
					$("#loginerr").css('display','none');
					$('#logstatus').html("");
					return true;
				}
			});
			return false;
		}
	});
Basically it validates the fields, if they dont validate it shows the error log, if it does it uses ajax to grab either a 'NO' or 'OK' for validating the user/pw in the database. However I can not get it to work. Ive verified the php script works fine. But im having trouble with the ajax response.

That last return false lets the script run sort of correctly, where as if your credentials are wrong it does display the error message, however if they are not and it hits the return true, it does not run the form action, it just hits the return false again.

But if you remove that last return false it doesnt work at all, it runs the form action valid or not.

Please help.

(Also dont worry about the hex_md5() javascript function, theres an external script handling that)