...
<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---
};