<form action="xxx" method="post" onsubmit="return check__()">function check__(){
            var uid = $('#uid').val();
            var pwd = $('#pwd').val();
            var ys = false;
            $.getJSON('xxx', xxx,function(req){
                if( req.success !=1 )
                {
                    //显示错误
                }
                else
                {
                    ys = true;
//这里alert(ys)查看  为  true
                 }            });
            return ys;
        }我的疑问是,就算返回为true  表单还是不提交,求解!!!!!

解决方案 »

  1.   

    ajax是异步的,所以还没执行完你ajax就已经return ys的默认值false了,当然无法提交,改ajax为同步的    function check__() {
            var uid = $('#uid').val();
            var pwd = $('#pwd').val();
            var ys = false;
            $.ajax({ url: 'xxx', data: 'xxx', type: 'GET',cache:false
            ,async:false///////////同步
            , success: function () {
                if (req.success != 1) {
                    //显示错误
                }
                else {
                    ys = true;
                    //这里alert(ys)查看  为  true
                }
            } });
            /*$.getJSON('xxx', xxx, function (req) {
                if (req.success != 1) {
                    //显示错误
                }
                else {
                    ys = true;
                    //这里alert(ys)查看  为  true
                }        });*/
            return ys;
        }