Ok so my problem is my Ajax Success Function is not working properly but IS WORKING properly on another web page. Annoying right? They have the same code(copy pasted it and edited) with different variables of course.
Working Code:
$.ajax({
type: 'POST',
url: 'login.php',
data: {
uname: username,
pass: password
},
success: function(html){
alert(html);
if(html=='true') {
$("#add_err").html("right username or password");
window.location="../home.php";
}
else {
$("#add_err").css('display', 'inline', 'important');
$("#add_err").html("<img src='images/alert.png' />Wrong username or password"+username+password);
}
},
beforeSend:function()
{
$("#add_err").css('display', 'inline', 'important');
$("#add_err").html("<img src='images/ajax-loader.gif' /> Loading...")
}
});
Login.php will just echo the word "true" or "false" depending on the query.
This is the Not Working Code:
$.ajax({
type: 'POST',
url: 'loginphp.php',
data: {
username1: username,
password1: password
},
success: function(html){
alert(html);
if(html=='true')
{
$("#errorlogin").html("right username or password");
window.location="../php/home.php";
}
else
{
$("#errorlogin").css('display', 'inline', 'important');
$("#errorlogin").html("<img src='images/alert.png' />Wrong username or password"+username+password);
}
},
beforeSend:function()
{
$("#errorlogin").css('display', 'inline', 'important');
$("#errorlogin").html("<img src='images/ajax-loader.gif' /> Loading...")
}
});
Loginphp.php will just echo the word "true" or "false" depending on the query.
as you can see they are technically the same but the not working code, what happens is even when the loginphp.php echoed TRUE, success function will go directly to ELSE.
I know it really echoed TRUE because I used "alert(html)" and it really shows TRUE.
But in the working code, the "if(html=='true')" is triggered. I don't know what is happening..