js导入Excel、ajax导入Excel、Excel导入、Excel导入数据库

这是通过表单上传的方式

HTML

<div class="input-group-wrap">
                            <div class="input-group">
                                <button filter="main-sjcl" class="btn btn-dark btn-labeled" style="float:left;">
                                    <i class="pli-down-4"></i>
                                    <span>选择Excel...</span>
                                </button>
                                <form id="uploadForm" enctype="multipart/form-data" style="float:left;">
                                    <input id="inputHover" type="file" name="inputHover" accept=".xlsx"
                                        style="width:94px;height:32px;position:absolute;left:0;cursor: pointer;opacity:0;float:left;" />
                                </form>
                                <button onclick="fileUp()" filter="main-sjcl" class="btn btn-primary btn-labeled"
                                    style="float:right;">
                                    <i class="pli-down-4"></i>
                                    <span>上传</span>
                                </button>
                            </div>
                        </div>

JS

function fileUp  () {//文件导入
                let files = $('#inputHover').prop('files');
                if (files.length < 1) {
                    return layer.msg('请选择导入文件!');
                }
                let formData = new FormData();
                formData.append('file', files[0]);
                formData.append('orgCode', this.orgCodeId);//字段key,val,如果没有就删掉
                $.ajax({
                    type: "POST",
                    url: "",
                    data: formData,
                    processData: false,
                    contentType: false,
                    success: function (result) {
                        if (result.success) {
                            layer.msg('上传成功!');
                            // this.initCalendar();
                        } else {
                            layer.msg('上传失败!');
                        }
                    },
                    error: function () {
                        layer.msg('上传失败!');
                    }
                });
            }

你可能感兴趣的:(前端)