Home > Backend Development > PHP Tutorial > javascript - AJAX提交表单同一个手机注册多个账号问题 ?

javascript - AJAX提交表单同一个手机注册多个账号问题 ?

WBOY
Release: 2016-06-06 20:28:01
Original
1426 people have browsed it

<code> // 提交表单
    $('#btn-confirm-login').on('click', function(){
       $('#form-to-post').ajaxSubmit({
            beforeSubmit: function(){
                if($('#input-account').val().length == 0) {
                     ui.error("请输入帐号");
                    $('#input-account').focus();
                    return false;
                }
                if($('#input-password').val().length == 0) {
                     ui.error("请输入密码");
                    $('#pinput-password').focus();
                    return false;
                }
                return true;
            }, 
            success: function(i){
                $('#error-msg-tip').html('<p>'+i.info+'</p>').show();
                if(i.status == 1){
                    if(i.data == 0){
                        window.location.href = U('public/Index/index');  
                    }else{
                        window.location.href = i.data;            
                    }
                }else if(i.status == 2){
                    var membs = i.data;
//                    console.log(membs);
                    var $con = $('#select-sub-acc');
                    $con.empty();
                    $.each(membs, function(i, e){
                        var $btn = $("<button></button>");
                        $btn.text(e.uname).data("acc", e.worket).data('uid', e.uid);
                        $btn.on('click', function(){
                            //var worket = $(this).data('acc');
                            var uid = $(this).data('uid');
                            $('#hidden-uid').val(uid);
                            //$('#input-account').val(worket);
                            $('#btn-confirm-login').trigger('click');
                        });
                        $con.append($btn);
                    });

                    var $dialog = $('#select-sub-acc').dialog({
                        autoOpen: false,
                        height: 200,
                        width: 300,
                        modal: true,
                        title:"请确定一个帐号"
                    });
                    $dialog.dialog('open');
                }
            },
            dataType: 'json'
        }); 
        return true; 
    }); 
    //var j17 = $.noConflict();
</code>
Copy after login
Copy after login
<code>当同一个手机注册多个账号时,会提醒用哪个账户登录,比如说这里,
显示的是 uname 不同的人名。

如果要改为 人名(身份)学校 这样显示,
其中 学校和人名在同一张表,身份在另一张表,
请问该怎么写?还有身份这个括号该怎么写?
</code>
Copy after login
Copy after login

这里主要用的是ajax,jquery, jquery form。

回复内容:

<code> // 提交表单
    $('#btn-confirm-login').on('click', function(){
       $('#form-to-post').ajaxSubmit({
            beforeSubmit: function(){
                if($('#input-account').val().length == 0) {
                     ui.error("请输入帐号");
                    $('#input-account').focus();
                    return false;
                }
                if($('#input-password').val().length == 0) {
                     ui.error("请输入密码");
                    $('#pinput-password').focus();
                    return false;
                }
                return true;
            }, 
            success: function(i){
                $('#error-msg-tip').html('<p>'+i.info+'</p>').show();
                if(i.status == 1){
                    if(i.data == 0){
                        window.location.href = U('public/Index/index');  
                    }else{
                        window.location.href = i.data;            
                    }
                }else if(i.status == 2){
                    var membs = i.data;
//                    console.log(membs);
                    var $con = $('#select-sub-acc');
                    $con.empty();
                    $.each(membs, function(i, e){
                        var $btn = $("<button></button>");
                        $btn.text(e.uname).data("acc", e.worket).data('uid', e.uid);
                        $btn.on('click', function(){
                            //var worket = $(this).data('acc');
                            var uid = $(this).data('uid');
                            $('#hidden-uid').val(uid);
                            //$('#input-account').val(worket);
                            $('#btn-confirm-login').trigger('click');
                        });
                        $con.append($btn);
                    });

                    var $dialog = $('#select-sub-acc').dialog({
                        autoOpen: false,
                        height: 200,
                        width: 300,
                        modal: true,
                        title:"请确定一个帐号"
                    });
                    $dialog.dialog('open');
                }
            },
            dataType: 'json'
        }); 
        return true; 
    }); 
    //var j17 = $.noConflict();
</code>
Copy after login
Copy after login
<code>当同一个手机注册多个账号时,会提醒用哪个账户登录,比如说这里,
显示的是 uname 不同的人名。

如果要改为 人名(身份)学校 这样显示,
其中 学校和人名在同一张表,身份在另一张表,
请问该怎么写?还有身份这个括号该怎么写?
</code>
Copy after login
Copy after login

这里主要用的是ajax,jquery, jquery form。

都用ajax了,自己拼装data发过去啰,还拘泥于一个form干嘛?

用JQuery和Ajax了那就用这样的代码吧
`
$('#btn-confirm-login').on('click', function(){

<code>$.ajax({
    beforeSend:function(){
            if($('#input-account').val().length == 0) {
                 ui.error("请输入帐号");
                $('#input-account').focus();
                return false;
            }
            if($('#input-password').val().length == 0) {
                 ui.error("请输入密码");
                $('#pinput-password').focus();
                return false;
            }
            return true;
        },
    dataType:"json",
    data:{"user":user,"pwsd":pwsd},
     success: function(i){
            $('#error-msg-tip').html('<p>'+i.info+'</p>').show();
            if(i.status == 1){
                if(i.data == 0){
                    window.location.href = U('public/Index/index');  
                }else{
                    window.location.href = i.data;            
                }
            }else if(i.status == 2){
                var membs = i.data;</code>
Copy after login

// console.log(membs);

<code>                var $con = $('#select-sub-acc');
                $con.empty();
                $.each(membs, function(i, e){
                    var $btn = $("<button></button>");
                    $btn.text(e.uname).data("acc", e.worket).data('uid', e.uid);
                    $btn.on('click', function(){
                        //var worket = $(this).data('acc');
                        var uid = $(this).data('uid');
                        $('#hidden-uid').val(uid);
                        //$('#input-account').val(worket);
                        $('#btn-confirm-login').trigger('click');
                    });
                    $con.append($btn);
                });

                var $dialog = $('#select-sub-acc').dialog({
                    autoOpen: false,
                    height: 200,
                    width: 300,
                    modal: true,
                    title:"请确定一个帐号"
                });
                $dialog.dialog('open');
            }
        }  
});</code>
Copy after login

`

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template