jquery中的$.post()方法无法给变全局变量的问题

今天遇到一个问题,在使用jquery的$.post()方法时,没有办法返回布尔值。

 

function check_exist() {
            
            var email = $('#email').val().Trim();
            url = "/Account/Exist";
            $.post(url, { email: email }, function (result) {
                if (result == "1") {
                    $('#email_error').html("该邮箱已经被注册!");
                    return false;
                }
                else if (result == "0")
                    
                    $('#email_error').html("");

            });
            return true;


        }

调用

 function regist() {
            if (!check_exist())
                return false;
            if (!check_pass())
                return false;
             ...........
}
if (!check_exist())本该发回的false结果,却返回了true,原来事因为$.post()方法在默认的时候是异步执行的。做如下设置即可 async:false
posted on 2014-06-17 12:04  jeemly  阅读(784)  评论(0编辑  收藏  举报