0
@ResponseBody
    @RequestMapping("/mailcode.do")
    public Map<String, Object> mailcode(String mail) throws Exception{
        RegisterPojo registerPojo = registerService.findBymail(mail);
        if(registerPojo == null){
            //生成四位随机数字
            Random random = new Random();
            int code = random.nextInt(9999-1000+1)+100;
            String mailcode = String.valueOf(code);
            Main.main(mail, mailcode);
             Map<String, Object> resultMap = new HashMap<String, Object>();
             resultMap.put("success", "success");
             resultMap.put("mailcode", mailcode);
            return resultMap;
        }
            return null;
            
    }
$.ajax({
                type:"POST",
                url :"/register/mailcode.do",
                data :{"mail":mail},
                datatype: "json",
                success:function(data){
                    if(data.success == 'success'){
                        alert("发送成功");
                    }else{
                        alert("该邮箱已经被占用");
                        return false;
                        }    
                    },
                error:function(){
                    alert("dasd");
                }
    });

求各位大哥帮帮忙
我刚打印了下data出来的这个玩意、、、、、、

3个回答

0

是訪問不controller 還是訪問了拿不到值? 你把 url :"/register/mailcode.do",中的register這個拿掉試一下

0
$.ajax({
                type:"POST",
                url :"/register/mailcode.do?mail="+mail,
                success:function(data){
                    console.log(data)
                    if(data.success == 'success'){
                        alert("发送成功");
                    }else{
                        alert("该邮箱已经被占用");
                        return false;
                        }    
                    },
                error:function(){
                    alert("dasd");
                }
    });
0

这个controller返回的不是JSON数据吧

撰写答案