discuz 后台ajax提交

discuz 后台ajax提交
在showformfooter()函数最后添加:
showformfooter();
// drch
$html =  <<< eot
    <script src="https://cdn.bootcdn.net/ajax/libs/layui/2.7.6/layui.js"></script>
    <script>
    window.onload=function(){
        addclick();
    }
    function send(e,t){
        e.preventDefault();
        t.disabled = "disabled";
        var ifame = parent.window.frames["main"] || window.frames["main"];
        var myform = parent.window.frames["main"].document.querySelector('#cpform') || document.querySelector('#cpform');
        var myformdata = new FormData(myform);
        myformdata.set('inajax','1');
        if (t.name){
            myformdata.set(t.name,'1');
        }
        var url = myform.action;
        xhr = new XMLHttpRequest;
        xhr.open("post",url);
        xhr.send(myformdata);
        xhr.onload=function(){
            if (xhr.readyState==4 && xhr.status==200){
                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.msg('success',{icon:1},{time:1000});
                });
                setTimeout(() => {
                    // location.reload();
                    ifame.document.write(xhr.responseText);
                    // ifame.location=ifame.location;
                }, 1000);
            } else {
                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.msg('error'+xhr.status,{icon:2},{time:1000});
                  });
                }
        }
    }		
    function addclick() {
        var btn = parent.window.frames["main"].document.querySelectorAll('.btn') || document.querySelectorAll('.btn');
        for (let t of btn){
            t.setAttribute("onclick","send(event,this)");
        }
    }
    </script>
eot;
echo $html;
huan

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: