ajax返回boolean的坑


前台ajax请求,后台返回boolean(代码如下)

    $.ajax({
        type : "post",
        data : {
                "xxx" : xxx
        },
        url: "/xxx/xxx.do",
        success: function (result) {
            console.log(result);
            console.log(typeof result);
            if (result) {
                alert(true);
            } else {
                alert(false);
            }
        }
    });

    @RequestMapping("test")
    @ResponseBody
    public boolean test() {
        return true;
    }

后台返回的Boolean类型,ajax是不认的,会简单的认为是string类型。需要将代码修改为如下

    $.ajax({
        type : "post",
        data : {
                "xxx" : xxx
        },
        url: "/xxx/xxx.do",
        success: function (result) {
            console.log(result);
            console.log(typeof result);
            if (result == "true") {
                alert(true);
            } else {
                alert(false);
            }
        }
    });

 
————————————————
版权声明:本文为CSDN博主「赵丙双」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_20919883/java/article/details/98482857


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM