zoukankan      html  css  js  c++  java
  • 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", "");

    });

    })

  • 相关阅读:
    svg文件使用highmap显示
    动静分离
    angular 零碎
    使用doxmate生成文档
    javascript之console篇
    java 中String与StringBuilder 效率
    highcharts 组合chart
    js 攻坚克难
    html base 又一重大发现
    sql 分析 依赖beanutils
  • 原文地址:https://www.cnblogs.com/chengmingxiaowu/p/7595268.html
Copyright © 2011-2022 走看看