Layui关闭弹出层并刷新父窗口

父页面点击

            $('#add').click(function () {
                layer.open({
                    type: 2,
                    title: '新增',
                    shade: 0.3,
                    maxmin: true,
                    resize: true,
                    area: ['800px', '700px'],
                    content: '/projectException/add',
                    success: function (layero, dIndex) {
                        $(layero).attr('minleft', '250px');
                    }
                });
            });

子页面表单提交

 /* 监听表单提交 */
            form.on('submit(formSubmit)', function (data) {
                var loadIndex = layer.load(2);
                $.ajax({
                    type: 'post',
                    url: '/projectException/save',
                    data: $("#exceptionForm").serialize(),
                    success: function (res) {
                        layer.close(loadIndex);
                        if (200 === res.code) {
                           layer.alert(res.msg, {
                                    icon: 1, title: '提示', skin: 'layui-layer-lan', closeBtn: 0
                             },
                              // 确认关闭页面,并刷新父页面
                            function () {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.location.reload();//刷新父页面,注意一定要在关闭当前iframe层之前执行刷新
                                parent.layer.close(index); //再执行关闭
                            });
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }
                });
                return false; //layui的button有一个点击刷新事件 阻止它的默认行为
            });

posted @ 2020-05-17 10:06  proper128  阅读(1122)  评论(0编辑  收藏  举报