Hello everyone,
I'm writing a basic form for user login on my website.
It has a simple username, password, submit button.
So far, the jQuery I have written works and it's as follows:
- $(document).ready(function() {
$('form#loginForm').submit(function() {
var values = $('#loginForm').serialize();
var myform_return = function(data) {
alert(data);
if(data == true){
alert('they equal');
return true;
}else{
alert('NOT equal');
return false;
}
}
$.post('validatelogin', values, myform_return, "json");
return false;
});
});
Here's the thing, it works just like it should up until the very end!
I have a function 'validatelogin' (called in $.post) which validates the entries.
If valid, it ultimately returns TRUE to the return "myform_return"
-
If not valid, it returns FALSE to the return "myform_return"
Those alerts you see in my return form are working (I get the "they equal" alert when the username/pass combo is correct, "NOT equal" when the form is incorrect)
HOWEVER, the form never submits. Ever.
I tried removing the
return false; at the very bottom (thinking the returns inside the if condition would handle it) but they don't. With that removed, the form submits everytime without ever validating.
What gives?!