zoukankan      html  css  js  c++  java
  • ajax封装

    ajax: {
    //返回弹出层信息
    showloading:function prg_show_load_layer(msg,timeout) {
    return $.layer.msg(msg,{icon:16,shade:[0.5,'#f5f5f5'],scrollbar:false,offset:'auto',time:timeout})
    },
    closeloading:function prg_close_load_layer(index) {
    $.layer.close(index);
    },
    successMes: function pre_show_tip_layer(){
    $.layer.msg("处理完成",{time:300,offset:'auto'});
    },
    get: function (url, param, doFn) {
    var options = {};
    var exp = new Date();
    exp.setTime(exp.getTime() + 40 * 60 * 1000);
    options.expires = exp;
    var token = gg.core.cookie.getValue("token");
    gg.core.cookie.setValue("token",token ,options);
    $.ajax({
    type: 'GET',
    url: url,
    data: param,
    dataType: "json",
    success: function (result) {
    if (result.code == 200) {
    if (doFn) doFn(result);
    }
    else if (result.code == 998) {
    $.layer.alert('用户登录超时,请重新登录!', {
    icon: 2,
    closeBtn: 0
    }, function () {
    window.location = "login.html";
    });
    return;
    }
    else {
    $.layer.alert(result.errMsg, {
    icon: 2,
    closeBtn: 0
    });
    return;
    }
    },
    error: function () {
    $.layer.msg("加载失败",{time:1000,offset:'auto'});
    },
    headers:{
    authKey: gg.core.cookie.getValue("token"),
    sessionId:gg.core.cookie.getValue("sessionId")
    },
    });
    }
    ,
    post: function (url, param, doFn) {
    var options = {};
    var exp = new Date();
    exp.setTime(exp.getTime() + 40 * 60 * 1000);
    options.expires = exp;
    gg.core.cookie.setValue("token", gg.core.cookie.getValue("token"),options);
    $.ajax({
    type: 'POST',
    url: url,
    data: param,
    headers:{
    authKey: gg.core.cookie.getValue("token"),
    sessionId:gg.core.cookie.getValue("sessionId")
    },
    dataType: "json",
    contentType: "application/json",
    success: function (result) {
    if (result.code == 200) {
    if (doFn) doFn(result);
    }
    else if (result.code == 998) {
    gg.core.cookie.deleteCookid("token")
    $.layer.alert('用户登录超时,请重新登录!', {
    icon: 2,
    closeBtn: 0
    }, function () {
    window.location = "login.html";
    });
    return;
    }
    else {
    $.layer.alert(result.errMsg, {
    icon: 2,
    closeBtn: 0
    });
    return;
    }
    },
    error:function(event){
    $.layer.msg("加载失败",{time:1000,offset:'auto'});
    }
    });
    }
    }
  • 相关阅读:
    基于HTML5的可预览多图片Ajax上传
    在linq查询环境下通过sql语句来访问数据库
    EF查询数据库框架的搭建
    用多线程处理后台业务,并提高处理速度
    WPF 大数据加载过程中的等待效果——圆圈转动
    .NET一个线程更新另一个线程的UI(两种实现方法及若干简化)
    通电螺线管与磁场方向
    MOS管与三极管
    word2007怎样从中间某一页开始设置页码
    word删除页眉横线
  • 原文地址:https://www.cnblogs.com/tutao1995/p/9777271.html
Copyright © 2011-2022 走看看