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