在 jquery ajax 函数中,我接收到服务器“true”或“false”字符串。然后我只知道结果,但只在 if 条件下得到 false。
$.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');
}
}
})
...
...
有人可以帮助我吗?
最佳答案
“结果”中可能有换行符或多余空格。
关于javascript - 比较 JavaScript 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10411150/