JQueryhttps://jquery.cuishifeng.cn/
xm-selecthttps://maplemei.gitee.io/xm-select/#/basic/use
treetable-layhttps://gitee.com/whvse/treetable-lay/wikis/pages
layui-soul-tablehttps://saodiyang.gitee.io/layui-soul-table/
OPTablehttps://hbangmao.gitee.io/OPTable/layui-op-table/demo/index.html
Dtreehttp://www.wisdomelon.com/DTreeHelper/
eleTreehttps://layuiextend.hsianglee.cn/eletree/

layui 第三方组件平台https://fly.layui.com/extend/

错误提示

Access to XMLHttpRequest at 'http://localhost:8080/api/user/login' from origin 'http://localhost

解决方案

1、HTML部分

ajax 请求加入 contentType: "application/x-www-form-urlencoded"
请求如下:

$.ajax({
            type: "post",
            url: 'url',
            contentType: "application/x-www-form-urlencoded",
            data: {"gameCode": 106, type: "2",version:1,uid:1},
            dataType: "json",
            success: function (data,status) {
                console.log(data);
            }
        });

2、PHP部分

PHP 文件中加入请求头部 header ('Access-Control-Allow-Origin: *') ;

<?php 
    header('Access-Control-Allow-Origin: *');
    $arr = [
        array('id'=>1,'title'=>'one1'),
        array('id'=>2,'title'=>'one2'),
        array('id'=>3,'title'=>'one3'),
        array('id'=>4,'title'=>'one4'),
    ];
    echo json_encode($arr);
 ?>

3、请求数据

微信截图_20201011010842.png

文章转自:https://learnku.com/articles/32041

<script type="text/javascript" src="/static/admin/libs/tinymce/tinymce.min.js"></script>
<script>
    layui.use(['form', 'layer'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        // 渲染富文本编辑器
        tinymce.init({
            selector: '#content_edit',
            height: 400,
            branding: false,
            language: 'zh_CN',
            plugins: 'code print preview fullscreen paste searchreplace save autosave link autolink image imagetools media table codesample lists advlist hr charmap emoticons anchor directionality pagebreak quickbars nonbreaking visualblocks visualchars wordcount',
            toolbar: 'fullscreen preview code | undo redo | forecolor backcolor | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | formatselect fontselect fontsizeselect | link image file emoticons charmap anchor pagebreak codesample | ltr rtl',
            toolbar_drawer: 'sliding',
            images_upload_url: '{:url("upload", ["upType" => "editor"])}',
            //images_upload_base_path:'/',
            convert_urls: false,
            file_picker_types: 'file,image,media',
            file_picker_callback: function (callback, value, meta) {
                //文件分类
                var filetype='.pdf, .txt, .zip, .rar, .7z, .doc, .docx, .xls, .xlsx, .ppt, .pptx, .mp3, .mp4';
                //后端接收上传文件的地址
                var upurl='{:url("Ajax/upload", ["upType" => "editor"])}';
                //为不同插件指定文件类型及后端地址
                switch(meta.filetype){
                    case 'image':
                        filetype='.jpg, .jpeg, .png, .gif, .jpeg';
                        upurl='{:url("upload", ["upType" => "editor"])}';
                        break;
                    // case 'media':
                    //     filetype='.mp3, .mp4';
                    //     upurl='upfile.php';
                    //     break;
                    case 'file':
                        filetype='.docx, .doc, .xls, .xlsx, .ppt, .pptx, .pdf, .zip, .rar';
                        upurl='{:url("upload", ["upType" => "editor"])}';
                        break;
                    default:
                }
                //模拟出一个input用于添加本地文件
                var input = document.createElement('input');
                input.setAttribute('type', 'file');
                //input.setAttribute('accept', filetype); 禁用扩展
                input.click();
                input.onchange = function() {
                    var file = this.files[0];
                    var xhr, formData;
                    xhr = new XMLHttpRequest();
                    xhr.withCredentials = false;
                    xhr.open('POST', upurl);
                    xhr.onload = function() {
                        var json;
                        if (xhr.status !== 200) {
                            failure('HTTP Error: ' + xhr.status);
                            return;
                        }
                        json = JSON.parse(xhr.responseText);
                        if (!json || typeof json.location !== 'string') {
                            failure('Invalid JSON: ' + xhr.responseText);
                            return;
                        }
                        callback(json.location, { title: file.name });
                    };
                    formData = new FormData();
                    formData.append('file', file, file.name );
                    xhr.send(formData);
                };
            },
            init_instance_callback: function (editor) {
                // 编辑器初始化完成以后的
                layer.closeAll('loading');
            }
        });

</script>

callback(json.location, { title: file.name });这里容易出错,原文是 callback(json.location);js报错。