XMLHttpRequest 上传文件,带进度条。(easyUI)

19 篇文章 0 订阅
17 篇文章 0 订阅
...
                    <td style="width:17px;height:40px;">文件内容</td>
                    <td style="width:83%;">
                        <input id="Document_filePath" data-options="buttonText:'选择文件',method: 'post',required:true"
                               style="width:100%;" class="easyui-filebox" name="blobupFile">
                    </td>
...                
  
    <div id="Document_progressbarDialog" class="easyui-dialog" style="width:425px;height:80px;padding:5px;" data-options="closed:true,modal:true, title:'上传文件中,请等待...'">
	    <div id="Document_progressbar" class="easyui-progressbar" style="width:400px;height:15px"></div>
    </div>
  //save上传文件
    Document.SaveUploadClick = function () {
    	var Document_filePath = $("#Document_filePath").filebox('getValue');
    	if(Document_filePath == null || Document_filePath == ''){
    		$.messager.alert('提示',"请选择要上传的文件!", 'info');
    		return ;
    	}
    	//$.messager.progress({title: '上传文件中', msg: '请等待',interval:1300});
    	
    	// ---XMLHttpRequest 上传文件 begin---
    	    var fileObj = document.getElementsByName("blobupFile")[0].files[0]; // js 获取文件对象
    	    if(fileObj.size > 104857600){
        		$.messager.alert('提示', "文件过大!不能超过100M", 'info');
        		return ;
            } 
    	    var FileController = 'SystemManager/SaveUploadFile.action?fileDsc=' + encodeURI(encodeURI($('#Document_TextBox_remark').textbox('getValue')));                    // 接收上传文件的后台地址 
            // FormData 对象
            var form = new FormData($( "#Document_form_Uploadfile" )[0]);
            // XMLHttpRequest 对象
            var xhr = new XMLHttpRequest();
            xhr.open("post", FileController, true);
            //关闭上传文件窗体
            Document.UploadDialogObj.dialog('close');
           //监听 
           xhr.upload.onprogress = function (evt) {
            	if(evt.total > 104857600){
            		$.messager.alert('提示', "文件过大!不能超过100M", 'info');
            	}else{
            		$("#Document_progressbarDialog").dialog("open");
            		if (evt.lengthComputable) {
                        $('#Document_progressbar').progressbar('setValue',Math.round(evt.loaded / evt.total * 100));
                    }
            	}
            }
            xhr.send(form);
            xhr.onload = function () {
            	$("#Document_progressbarDialog").dialog("close");
            	if (this.status == 200) {
            		var data = $.parseJSON(this.response);
                    if (data.success) {
                    	//重新加载列表
                        $('#Document_datagrid_SysDocument_Table').datagrid({
                            method: 'post',
                            url: 'SystemManager/GetUploadFile.action'
                        });
                    } else {
                        $.messager.alert('错误', data.message, 'error');
                    }
            	}else{
            		$.messager.alert('错误', "出错了,请联系管理员!", 'error');
            	}
            };
    	// ---XMLHttpRequest 上传文件 end---
    };

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值