function getCookie(name){
    var x = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return x ? x[1]:undefined;
}

// 搜索时间戳 距当前时间几分钟 几小时 几天 前
function dealTimestmp(class_name,data_name) {
    $("."+class_name).each(function () {
        $(this).html(timeConvert($(this).attr(data_name)))
    })
}
// 返回距离当前的时间
function timeConvert(a) {
    if (a) {
        a = parseInt(a);
        var b, d, c;
        b = parseInt((new Date).getTime() / 1E3) - a;
        c = parseInt(b / 86400);
        d = parseInt(b / 3600);
        b = parseInt(b / 60);
        if (0 < c && 4 > c) return c + "\u5929\u524d";
        if (0 >= c && 0 < d) return d + "\u5c0f\u65f6\u524d";
        if (0 >= d && 0 < b) return b + "\u5206\u949f\u524d";
        if (b<60) return "\u521a\u521a";
        a = new Date(1E3 * a);
        return a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() +"日"
    }
    return ""
}
var _xsrf = getCookie("_xsrf");
// 提交返回数据类型为json
var datatype='json';

if ($('#login_ok').length || $('#login_no').length) {
    // 存在id 'your-id'，执行操作
    $('#login_ok').hide();
    $('#login_no').hide();
    var url='/ajax_user/operate';

    $.ajax({
        url: url,
        cache: false, //同步方式 true为异步方式
        method: 'post',
        data: {
            ac: 'mylogin_state',
            datatype: datatype,
            _xsrf: _xsrf,
        },
        //成功
        success: function (data) {
            if (data.resultcode == 0) {
                // 登录成功
                $('#login_ok').show();
                $('#login_no').hide();
            } else {
                // 未登录
               $('#login_ok').hide();
                $('#login_no').show();
            }
        },
        //整个请求完成后，调用
        complete: function (data) {

        },
        //出错时，调用
        error: function (data) {
            console.log(data.resultcode);
            alert("服务太繁忙，你也累了，喝杯咖啡歇息歇息！");
            return false;
            // msg="服务太繁忙，你也累了，喝杯咖啡歇息歇息！";
        }
    })
}