MarkJane
5/18/2017 - 6:57 AM

表单提交上传文件

表单提交上传文件

 $("#import").change(function(){
        if (!(window.File || window.FileReader || window.FileList || window.Blob)) {
            layer.msg("请使用谷歌浏览器!", {time:3000});return;
        }
        var files = $(this).prop('files');//获取到文件列表
        var path = $(this).val();
        var ext = path.slice(path.lastIndexOf(".") + 1).toLowerCase();
        //console.log(path,ext);
        if (ext != 'xls' && ext != 'xlsx') {
            layer.msg("导入的文件格式不正确,请选择 xls或者xlsx格式", {icon:5, time:3000,shade:0.5,shadeClose:true});
            return false;
        }
        var formData = new FormData();
        formData.append("excelDate",$("#excelDate").val());
        formData.append("excel", $("#import").get(0).files[0]);
        var msgIndex = layer.msg('正在导入,请耐心等待···',{time: 0,shade:0.5,shadeClose:false});
        $.ajax({
            type:"POST",
            data:formData,
            url: "<?php echo base_url('data_analysis/slidetime_statistic/doexcel');?>",
            success:function(data){
                var _ = $.parseJSON(data);
                var icon = _.status ? 6 : 5;
                layer.close(msgIndex);
                layer.msg(_.tip, {icon:icon, time:3000,shade:0.5,shadeClose:true});
                $('#import').val('');
            },
            cache: false,
            contentType: false,
            processData: false
        });
    });