How to get success ajax response value/string and use it on the if condition?
php will echo "valid" if success, else it will echo "invalid".
$("#submit-login").click(function () {
var email = $('#mailInput2').val();
var pass = $('#passInput2').val();
$.ajax({
url: 'func_login.php',
data: 'login_email='+email+'&login_password='+pass,
type: 'POST',
success: function(data) {
alert(data); //alert show 'valid'
$('#test').html(data); //working, #test show 'valid'
if(data == "valid"){
$('#test').html(data); //not working when this inside 'if'
}
//I also tried
//if(data['valid']){}
//if(data === "valid"){}
//if(data == 'valid'){}
//if(data.content == 'valid'){}
},
error: function(xhr, textStatus, error){
console.log(xhr.statusText);
console.log(textStatus);
console.log(error);
}
});
});
dataType : "text"
and try again.