在jquery ajax函数中,我收回服务器的“真”或“假”字符串。然后我只知道结果,但只有在条件不成立的情况下。在javascript中比较字符串
$.ajax({
...
success: function(result) {
if(result == "true"){ // false???????
alert('true');
} else {
alert('false');
}
}
})
...
$.ajax({
...
success: function(result) {
var result2 = String(result);
alert(result2); // true
alert(typeof result2); // String
alert(typeof "true"); // String
if(result2 == "true"){ // false???????
alert('true');
} else {
alert('false');
}
}
})
...
...
有人能帮助我吗?
如果你的解释说'result =='true''是'false',那么'result'不是''true''。就这么简单。你可能想要检查你是否假设'结果是,真的在持有。尝试'console.log(result)'。 – Yoshi
您确定结果中包含“true”吗? –
您正在使用jQuery,而jQuery有时使用“智能猜测”来计算结果类型。试试'result === true'。它可能已变成布尔型。 – Joseph