zoukankan      html  css  js  c++  java
  • 文件上传

    <div class="row">
        <div class="col-md-12">
            <section class="panel">
                <header class="panel-heading">
                    预算调整模板导入
                </header>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-lg-12">
                                <form id="defaultForm" method="" class="form-horizontal recoveryNodeForm" action="">
                                    <div class="col-lg-12">
                                        <div class="form-group">
                                            <label class="col-lg-3 control-label">导入文件</label>
                                            <div class="col-lg-6">
                                                <input type="file" class="form-control" style="height:36px;" name="uploadFile" id="uploadFile"/>
                                            </div>
                                            <button type="button" class="btn btn-primary" id="uploadExcel">上传提交</button>
                                        </div>
                                    </div>
                                    <input type="hidden" name="pkId" value="" />
                                </form>
                            </div>
                        </div>
                        <div>
                            <span><b>导入结果反馈</b></span>
                            <ul id="exportResult"></ul>
                        </div>
                    </div>
                        
            </section>
        </div>
    </div>
    
    <!-- 工具JS由开发人员编写 -->
    <script th:inline="javascript">
        /*<![CDATA[*/
    $(function(){
        $(".recoveryNodeForm").bootstrapValidator({
            message: 'This value is not valid',
            live: 'submitted',
            fields: {/*验证*/
                uploadFile: {
                    message: '导入文件无效',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '导入文件不能为空'
                        },
                        regexp: {
                            regexp: /.xl(s[xmb]|t[xm]|am|s)$/,
                            //regexp: /.xls$/,
                           // extension: 'zip,rar,doc,docx,pdf',
                            message: '导入文件类型必须是excel'
                        }
                       /* uploadFile: {
                              extension: 'zip,rar,doc,docx,pdf',
                              //  type:'zip,rar,doc,docx,pdf',
                                maxSize: 1024*100,
                                minSize: 1024,
                                message: '仅支持大小在1M~5M之间,类型是zip,rar,doc,docx,pdf文件!'
                        } */
                    }
                }
            }
        })
    });
        $("#uploadExcel").on("click","",function () {
        //    $('#uploadExcel').clear(); 
            $(".recoveryNodeForm").data("bootstrapValidator").validate();
            var flag = $(".recoveryNodeForm").data("bootstrapValidator").isValid();
            if(!flag){
                //未通过验证
                return false;
            }
            var fileObj = document.getElementById("uploadFile").files[0];
            var formFile = new FormData();
            formFile.append("file", fileObj);
            var data = formFile;
            layer.msg('请等待...', {icon: 6,time: 2500});
            $.ajax({
                url: "budgetOaController/upload",
                data: data,
                type: "Post",
                dataType: "json",
                cache: false,//上传文件无需缓存
                processData: false,//用于对data参数进行序列化处理 这里必须false
                contentType: false, //必须
                success: function (result) {
                    var htmlstr = '';
                    if(result.success==false){
                        htmlstr = '<li>'+result.msg+'</li>';
                    } else {
                        htmlstr = '<li>'+result.msg+'上传成功</li>';
                    }
                    $('#exportResult').html(htmlstr);
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    layer.msg("系统错误, 请重新登录。",{icon: 2});
                }
            });
            
            var file = document.getElementById('defaultForm');
            file.value = ''; //清空缓存文件
        });
        
        /*]]>*/
    </script>

    图示:

  • 相关阅读:
    使用bottle进行web开发(2):http request
    使用bottle进行web开发(1):hello world
    python modules
    python的class的__str__和__repr__(转)
    functools模块方法学习(1):partial
    bottle框架学习(2):变量定义等
    VisualSVN_Server安装_配置图文教程
    管理的艺术--达尔文进化论:适者生存 末位淘汰
    LINUX怎么修改IP地址
    Cent OS 命令行和窗口界面默认登录切换方法
  • 原文地址:https://www.cnblogs.com/Steven5007/p/10239595.html
Copyright © 2011-2022 走看看