I just can't get it to work that I'm using the response of an ajax call in an if/else statement. If I output the response in console.log() it shows that it is correctly set, but the simple if/else statement just doesn't work.
function check_foo() {
dataString = {action: 'do_this'};
$.ajax({
type: "POST",
url: "ajax.php",
data: dataString,
success: function(foo) {
console.log('foo='+foo); // output: foo=ok
if (foo=="ok") { // should be true, but isn't
console.log('foo='+foo+' -> OK');
} else { // instead this gets output
console.log('foo='+foo+' -> FAIL'); // output: foo=ok -> FAIL
}
}
});
}
check_foo();
ajax.php:
echo 'ok'; // This is the result of the call
so foo is correctly set as 'ok' (as shown in console.log), but the if/else doesn't seem to recognize it...
Any help would be very much appreciated!
elsefire?'ok'in the data.if ($.trim(foo)=="ok")