变量赋值未在JQuery ajax方法中执行

时间:2018-09-13 20:19:19

标签: jquery ajax

我有一个表单,想使用api(register-checker.php文件)进行验证:

var email_status = false;
    var email = $("#register_email").val();
        $.ajax({
            url: "engine/ajax/register-checker.php",
            dataType: "html",
            type: "GET",
            data: {
                field : "email",
                value : email
            },
            success: function(result){
                if(result == "false"){
                    $("#register_email_error").text("this email used by another user");
                    $("#register_email_error").fadeIn();
                }else{
                    console.log("here is executed");
                    email_status = true;
                }
            }
        });   console.log("email_status: " + email_status);

完成验证后,register-checker.php文件返回“ true”,console.log(“此处已执行”)执行,但是当我在文件末尾记录email_status变量时,控制台显示“ email_status:false” 。 怎么了?

0 个答案:

没有答案