I made an if and else statement in Javascript, but I can’t get it to work.
This is my code, I hope you people will see whats wrong
var int = "";
function fbLoop (userLoop)
{
int=setInterval(function(){fbCheckloop(userLoop)},1000);
}
function fbCheckloop(userCheck)
{
if(userCheck.login != 'false')
{
window.clearInterval(int);
console.log(userCheck);
fbUpload(userCheck);
}
else
{
$.get("uploadtofb.php", {functie: "checklogin", fotonaam: userCheck.fotonaam}, fbCheckloop);
}
}
The if(userCheck.login != 'false') doesn’t work.
The console.log(userCheck); shows this
{"login":"false","fotonaam":"NAME"}
So according to the console log he have to do the else, but he does the if statement.
What did I do wrong?
The userCheck is coming from this:
return json_encode($checklog = array(
'login' => 'false',
'fotonaam' => $_GET['fotonaam']
));
Are you sure that
userCheckis a JavaScript object, and not a JSON string that has to be parsed? Your current console log result makes me suspect that it is. What doesconsole.log(typeof userCheck)yield?If it is, use