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有一個點擊刷新事件 阻止它的默認行為
            });


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM