1. 程式人生 > >jQuery+ajax實現網站登錄登出

jQuery+ajax實現網站登錄登出

logout attr 參考 rip index time cli dex .get

function logout() {
            $(‘#LoadingStatus‘).show();
            $.ajax({
                type:"POST",
                url:"/index.php?r=user/ajaxlogout",
                dataType:‘json‘,
                success: function(msg){
                    if(msg[‘status‘] == true){
                        $(
‘#LoadingStatus‘).hide(); $(‘#login‘).show(); $(‘#login_ok‘).hide(); var html1 = "<a rel=‘nofollow‘ href=‘http://www.chinaobd2.com/login.php‘>Sign In</a> | <a rel=‘nofollow‘ href=‘http://www.chinaobd2.com.com/reg.php‘>Join Free</a> | <strong><a rel=‘nofollow‘ href=‘http://www.chinaobd2.com.com‘>My ismap.com</a></strong>"; $(
‘#head_login‘).html(html1); $(‘#publish‘).attr(‘href‘,domain); }else{ $(‘#LoadingStatus‘).hide(); alert(msg[‘error‘]); } } }); }

jQuery+ajax實現網站登錄登出

$(function() {
            menu();
            var now = new Date();
            $.ajax({
                type: "GET",
                url: "/index.php?r=user/ajaxGetLoginUser",
                data: ‘&date=‘ + now.getTime(),
                dataType: ‘json‘,
                cache: ‘false‘,
                success: function (msg) {
                    if (msg[‘status‘] == true) {
                        $(‘#login‘).hide();
                        $(‘#user‘).text(msg[‘user‘]);
                        if (msg[‘pay‘]) {
                            $(‘#pay‘).text(‘(‘ + msg[‘pay‘] + ‘)‘);
                        }
                        if (msg[‘unpaid‘]) {
                            $(‘#unpaid‘).text(‘(‘ + msg[‘unpaid‘] + ‘)‘);
                        }
                        if (msg[‘pass‘]) {
                            $(‘#pro_pass‘).text(‘(‘ + msg[‘pass‘] + ‘)‘);
                        }
                        if (msg[‘nopass‘]) {
                            $(‘#pro_nopass‘).text(‘(‘ + msg[‘nopass‘] + ‘)‘);
                        }
                        $(‘#login_ok‘).show();
                        var html1 = "Welcome,<a href=‘"+domain+"‘ >" + msg[‘user‘] + " </a>";
                        html1 += " | <a href=‘javascript:void(0)‘ onclick=‘logout()‘>Sign out </a> | <strong><a href=‘http://www.chinaobd2.com‘>My ismap.com</a></strong>";
                        $(‘#head_login‘).html(html1);
                        $(‘#publish‘).attr(‘href‘, domain);
                    }
                }
            });
        });

這段是chinaobd2登出代碼,僅供大家參考

jQuery+ajax實現網站登錄登出