比较javascript中的String

Dan*_*ani 0 javascript string compare

在jquery ajax函数中,我接受了服务器"true"或"false"字符串.然后我只知道结果但只是在条件下得到假.

 $.ajax({
    ...
        success: function(result) {
              if(result == "true"){   // false???????
                    alert('true');
                } else {
                    alert('false');
                }
             }
        })
    ...
Run Code Online (Sandbox Code Playgroud)
$.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');
            }
         }
    })
...
Run Code Online (Sandbox Code Playgroud)

...

有人可以帮帮我吗?

Dan*_*ndy 5

"结果"中可能有换行符或额外空格.