QUESTION:いくつかの奇妙な理由でJS!レスポンスでP!= "P"が表示されるのはなぜですか?
は、私のJSONから "P" がtrueを返す "P" が、 "P" == "P" に等しいではないようです。これは意味がありません。
どこかのデータ型の問題があるはずです。
どうすればresponse.charAt(0) == "P"
が返されるのを確認できますか?true
?
CODE:
$.ajax({
type: "POST",
url: "/1/1",
data: someData,
}).done(function(response) {
console.log("p" == "P"); //prints false
console.log("P" == "P"); //prints true
console.log("RESPONSE: "+response); //prints "Primary"
console.log("RESPONSE FIRST LETTER: "+response.charAt(0)); //prints P
console.log("RESPONSE BOOL P :"+response.charAt(0)=="P");
//
//false for some reason, should be true
//
if (response.charAt[0] == "P") {
console.log("1");
localStorage.setItem("error_msg_local", message);
} else if (response.charAt[0] == "L") {
localStorage.setItem("success_msg_local", message);
console.log("2");
} else {
localStorage.setItem("error_msg_local", "Internal error. Please try again.");
console.log("3");
// 3 gets logged when it should have been 1
}
});
質問は何ですか – Sajeetharan
なぜdownvoteですか? –
@Sajeetharan "どうすればresponse.charAt(0)==" P "がtrueを返すのですか? –