Layui 子框架 toast

                function myAjaxPost(url, data, successCallback, errorCallback, completeCallback) {
                    $.ajax({
                        type: "POST",
                        url: url,
                        data: data,
                        dataType: "json",
                        beforeSend: function() {
                            parent.layer.msg("数据正在提交...",
                                {
                                    icon: 4,
                                    offset: 'rt',
                                    anim: 6,
                                    time: 3000,
                                    skin: "layui-bg-blue"
                                });
                        },
                        success: function(msg) {
                            if (msg.code === 0) {
                                parent.layer.msg(msg.message,
                                    {
                                        icon: 1,
                                        offset: 'rt',
                                        anim: 6,
                                        time: 3000,
                                        skin: "layui-bg-green"
                                    },
                                    function() {
                                        if (typeof(successCallback) === 'function') {
                                            successCallback();
                                        }
                                    });
                            } else {
                                parent.layer.msg(msg.message,
                                    {
                                        icon: 2,
                                        offset: 'rt',
                                        anim: 6,
                                        time: 3000,
                                        skin: "layui-bg-red"
                                    },
                                    function() {
                                        if (typeof(errorCallback) === 'function') {
                                            errorCallback();
                                        }
                                    });
                            }
                        },
                        error: function(req, status, error) {
                            parent.layer.msg(error,
                                {
                                    icon: 2,
                                    offset: 'rt',
                                    anim: 6,
                                    time: 3000,
                                    skin: "layui-bg-red"
                                },
                                function() {
                                    if (typeof(errorCallback) === 'function') {
                                        errorCallback();
                                    }
                                });
                        },
                        complete: function() {
                            if (typeof(completeCallback) === 'function') {
                                completeCallback();
                            }
                        }
                    });

                }

 

posted @ 2022-05-08 12:12  月渊  阅读(379)  评论(0)    收藏  举报