• jquery ajax常用的登录登出


    整理jquery+ajax的登录登出方法。

       

      //登录

    var currentUserId = -1;

    $(function() {

    var timestamp = (new Date()).valueOf();

    $.ajax({

    type: 'POST',

    url: '../m/user/getCurrentUser',

    dataType: 'json',

    data: {

    t: timestamp

    },

    success: function(data) {

    var isOK = false;

    if(data.code == 1) {

    var currentUser = data.object;

    if(currentUser) {

    $(".to_login").html('<a href="#">退出登录</a>');

    $(".to_login").click(function() {

    logout();

    });

    $(".wel_username").html("欢迎您,<span >" + currentUser.userName + "</span>");

    currentUserId = currentUser.userId;

    $(".get_username").html(currentUser.userName);

    if(currentUser.userId != 1) {

    $("#systemManage").hide();

    }

    if(currentUser.roleId == 3) {

    isOK = true;

    } else {

    logout();

    }

    }

    }

    //登录失败

    if(!isOK) {

    window.location.href = "login.html";

    }

     

    }

    });

    });

         //登出

    function logout() {

    $.ajax({

    type: 'post',

    url: '../m/user/logout',

    dataType: 'json',

    success: function(data) {

    if(data.code == 1) {

    window.location.href = "login.html";

    }

    }

    })

    }

    //首页

    $(document).ready(function() {

    $('.to_login').click(function() {

    $.cookie("autoLogin", 0);

    $.cookie("password", "");

    });

    })

  • 相关阅读:
    洛谷 P1414 又是毕业季II Label:None
    洛谷 P1372 又是毕业季I Label:None
    洛谷 P1111 修复公路 Label:并查集
    高精度特别策划 加减乘除余~~~
    洛谷 P1967 货车运输 Label: 倍增LCA && 最小瓶颈路
    数组指针和指针数组的区别
    堆和栈的区别
    JAVA8 十大新特性详解
    自己在菜单栏中加了一项打开文件的菜单后窗口不刷新 单击才刷新
    Windows 7 OpenGL配置
  • 原文地址:https://www.cnblogs.com/chengmingxiaowu/p/7595268.html
Copyright © 2020-2023  润新知