layui 中layer.load 与ajax 结合使用

 

1、load方法提供三种风格供选择。

方法一:loadIndex = layer.load(); //不传参,默认0

方法二:loadIndex = layer.load(1); // 1,另外一种风格

方法三:loadIndex = layer.load(2,{time:10*1000}); //2,换一种风格;time设置最长等待时间

load默认不会关闭,需要在complete回调中关闭。

2、项目中调取接口时,如果等待时间过长,则需要设置

$(function () {
    var loadIndex = '';
    $.myAjax ({
        urlurl,
        type"GET",
        headers: {'Content-Type''application/json'},
        beforeSend: function () {
            loadIndex = layer.load(1, {
                shade: [0.1, '#fff']
            });
        },
        complete: function () {
            layer.close(loadIndex);
        },
        success: function (res) {},
        error: function (e) {}
    });
});

 

 

var loadIndex2;

 

beforeSend:function(){
    loadIndex2 = layer.load(0, {
        shade: [0.5,'gray'] //0.1透明度的灰色背景
    });
},
 
 
complete:function(){
    layer.close(loadIndex2);
},