Im making an ajax login form. When a user logs in with the wrong password login.php will return "Incorrect password". But javascript doesn't seem to be picking it up.
$('#login_btn').click(function(){
var username = $('#login_username').val();
var password = $('#login_password').val();
$.post("login.php", { username: username, password: password },
function(data){
if(data == 'Incorrect password'){
$('#login_callback').html(data);
}
else{
$('#login').html(data);
}
}
);
});
I can login fine, but its just when its the wrong password.
Try changing your request to use $.ajax instead of $.post since $.post silently fails.
$.ajax({
type: "POST",
url: "login.php",
dataType: 'text',
data: { username: username, password: password },
success: function(data) {
if(data == 'Incorrect password'){
$('#login_callback').html(data);
}
else{
$('#login').html(data);
}
},
error: function(msg) {
alert("O NOES");
}
});
This is based on my theory that login.php
returns a non-200 response on failure. Just a hunch though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With