Hi
After learning jquery for about a month, I make an attempt to make username & password authentication form. Howver, i get stuck 2 days now, and i will soon start bumping my head against the wall.
What I am trying to do is if user enter the wrong username or password to display the message without reloading the page, and if he enter right username and password, php page that make the check against the database should redirect the user.
I will post my function(s) that doesnt work here, and if anyone can help me to make them work it will be great. If not, any link to some step by step tutorial will also do the trick (under the condition that jquery library is used)
Here is what i have now, and it work partially because if the user enter wrong username and password messge is shown to him, but if he enter right username and password, he remain stuck on the login page, due the e.preventDefault()
function 1:
formLogin.on('submit', function(e){
$.ajax({
type: 'POST',
url: 'loginCheck',
data: $(formLogin).serialize(),
dataType: 'json',
success: function(errorMessage){
if(errorMessage.length > 0) {
$('#errorMessageTop').fadeIn();
}
}
});
e.preventDefault();
});
function 2:
formLogin.on('submit', function(e){
$.post('loginCheck',
formLogin.serialize(), function(errorMessage) {
if(errorMessage.length > 0) {
$('#errorMessageTop').fadeIn();
} else if (errorMessage.length == 0) {
console.log(errorMessage.length);
}
});
return e.preventDefault();
});
Regards, Zoreli