关于Ajax:javascript字符串的奇怪比较

javascript strange comparison of strings

本问题已经有最佳答案,请猛点这里访问。

我有一个Ajax函数,它将电子邮件发送到某个地方,并从一个json对象接收来自服务器的响应,类型为success或error。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$("#submit_btn").click(function(event) {
    event.preventDefault();

    var post_data = {
        'email': $("#email").val()
    };
    $.post("sendEmail.php", post_data ).done(function(response){
        if(response.type == 'success'){
            $("#sentmail").fadeIn("slow")
            setTimeout(function(){
                $("#mail").val("Enter your email here");

                $("#sentmail").fadeOut("slow")  
            },3000);
        }
        else{
            $("#sentmailfail").fadeIn("slow")
            setTimeout(function(){
                $("#mail").val("Enter your email here");

                $("#sentmailfail").fadeOut("slow")  
            },3000);
        }
    },"json")
});

有趣的是,如果我是console.log(response),我会得到例如{"type":"success","desc":"something"},然后直接得到console.log( (response.type =="error") ) // TRUE

如果我从响应中获取控制台日志并将其分配给一个变量,例如a = {"type":"success","desc":"something"},那么a.type =="error"是错误的。

有人能解释一下吗?


(P)如果EDOCX1的输出是英文的(p)字母名称(P)Then EDOCX1 original 1 is most likely still a string(containing JSon),and strings don't have a EDOCX1 psychological 2 property:(p)字母名称(P)Objects usually look differently in the console:(p)字母名称(P)Solution:Parse the string first:(p)字母名称(P)Related to JQERY:(p)(P)I noticed that you intend to let Jquery parse the JSon for you,but you are passing EDOCX1 English 3 to the wrong function.You have to pass it to EDOCX1 to EDOCX1 music 4,not to EDOCX1 music 5:(p)字母名称(P)他们不需要你来阻止它。(p)(P)Javascript的Parse JSon?(p)