表单提交前检查,ajax的问题

时间:2022-11-06 22:37:08
<button class="submit" type="submit" onclick="return checkForm()"><span>提交</span></button>

    //提交表单前的检查
    function checkForm()
    {
        var platfrom_num = $('[name="platfrom_num"]').val(); //平台编号只能是数字或者字母
        var reg_1 = /^((?!\W).)*$/;
        if(reg_1.test(platfrom_num)){
            if(checkAdminName()){
                return true;
            }else{
                return false;
            }
        }else{
            art.dialog.tips("平台编号只能是数字或者字母!");
        }
    }

    function checkAdminName()
    {
        var admin_name = $('[name="admin_name"]').val();
        var admin_id = $('[name="admin_id"]').val();
        var id = $('[name="id"]').val();
        var temp = 1;
        $.ajax({
            url:"{url:/platfrom/check_admin}",
            type:"post",
            async: false,
            data:{id:id,admin_name:admin_name,admin_id:admin_id},
            success:function(res){
                console.log(res.code);
                if(!res.code){
                    art.dialog.tips("管理员账号已存在");
                    temp=0;
                }
            },
        })
        return temp;
    }