一开始ajax执行了请求,并且也更新成功了,但是没有走success,报status: "parsererror"错,后来发现是dataType:‘json’要注释掉,因为我controller返回的不是对象,是字符串
               $.ajax({
                    type: ‘POST‘,
                    url: ‘/updateagent‘,
                    data:JSON.stringify(data),
                    /*dataType: ‘json‘,*/
                    contentType:"application/json",
                    success: function(result){
                        layer.msg(‘修改成功!‘,{icon:1,time:1000,
                        end:function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.$(‘.btn-refresh‘).click();
                            parent.layer.close(index);
                        }
                        });
                    },
                    error:function() {
                        layer.msg(‘error!‘,{icon:1,time:1000,
                            end:function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.$(‘.btn-refresh‘).click();
                                parent.layer.close(index);
                            }
                        });
                    }
                });
还有一个问题是layer.msg没有执行,ajax是异步的,我一开始把parten.layer.close();放在ajax后面了,layer.msg和layer.close()一起执行了,解决方法是把layer.close(),放到layer.msg里面的end:function()里面
刷新关闭弹窗后,刷新界面。我一开始把刷新,window.parent.location.reload();写在上面的关闭弹窗后,不知道为啥一直不执行,后来在layer.open()里面end:funtion()刷,可行了。
function member_add(title,url,w,h){
        layer_show_add(title,url,w,h);
    }
    function layer_show_add(title,url,w,h){
        if (title == null || title == ‘‘) {
            title=false;
        };
        if (url == null || url == ‘‘) {
            url="404.html";
        };
        if (w == null || w == ‘‘) {
            w=800;
        };
        if (h == null || h == ‘‘) {
            h=($(window).height() - 50);
        };
        layer.open({
            type: 2,
            area: [w+‘px‘, h +‘px‘],
            fix: false, //不固定
            maxmin: true,
            shade:0.4,
            title: title,
            content: url,
            end:function () {
                window.location.reload();
            }
        });
    }
ajax请求里面的success和error里面的layer.msg,刷新父界面,碰到的一些问题
原文:https://www.cnblogs.com/lhh666/p/12452001.html