XMLHttpRequest文件上传,并显示进度条
2016-06-05 22:51
549 查看
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | function submitRequest(callback) { var apkFile = document.getElementById("file").files[0]; if (apkFile) { var fileName = apkFile.name; var suff = fileName.substring(fileName.lastIndexOf('.') + 1,fileName.length); if (suff != "apk") { $.messager.alert("提示", messageCreator("文件格式必须为apk!")); return; } } var fd = new FormData(); if (apkFile) { var apkName = apkFile.name; fd.append("apkName", apkName); fd.append("apkFile", apkFile); } var seq = $('#inputSeq').val(); fd.append("seq", seq); fd.append("developer", $('#inputDeveloper').textbox('getText')); fd.append("isTop", $('#inputIsTop').combobox('getValue')); fd.append("isRecommend", $('#inputIsRecommend').combobox('getValue')); fd.append("isRelease", $('#inputIsRelease').combobox('getValue')); fd.append("description", $('#inputDescription').val()); var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false); xhr.open('POST', AppContextPath + "/rest/app/save_app", true); /* xhr.onload = function() { $.messager.alert("提示", "添加成功", null, function() { window.top.iframeNavigator('ifrmContent','service/app_main.html'); if (callback != null) callback(); }); }; */ xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200){ $.messager.alert("提示", "添加成功", null, function() { window.top.iframeNavigator('ifrmContent','service/app_main.html'); if (callback != null) callback(); }); }else if(xhr.readyState == 4&& xhr.status != 200){ var jsonError = eval("(" + xhr.responseText + ")"); var errorType = jsonError.type; if(errorType == "ApkDuplicate"){ $.messager.alert("提示", "该Apk已经上传!", null, function() {window.top.iframeNavigator('ifrmContent','service/app_main.html'); }); } } }; xhr.send(fd); } function uploadProgress(evt) { if (evt.lengthComputable) { var percentComplete = Math.round(evt.loaded * 100 / evt.total); document.getElementById('progressNumber').innerHTML = '<font color=red>当前进度:'+percentComplete.toString() + '%</font>'; } else { document.getElementById('progressNumber').innerHTML = 'unable to compute'; } } |
相关文章推荐
- 20159217《网络攻防实践》第十四周学习总结
- UVA1590 IP网络(IP Networks)
- 解决IdTCPClient和IdTCPServer通信中文乱码问题
- iOS开发网络篇—网络编程基础
- IO多路复用(select poll epoll)
- 5.3 误差反向传播
- 访问控制列表实验
- CNN(卷积神经网络)、RNN(循环神经网络)、DNN(深度神经网络)的内部网络结构有什么区别?
- TimesTen 数据库复制学习:6. 利用STORE关键字设定复制网络传输的属性
- 神经网络算法的python实现
- TimesTen 数据库复制学习:5. 设定复制网络传输的return service
- 表单+servlet 网络调查表
- 【JavaWeb开发】用Apache的HttpClient4.5完成HttpPost请求
- android studio导入xutils编译时报错:找不到HttpRequestBase
- NAS 厂商的简单总结
- httpd之个人站点
- LINUX系统全部参数 sysctl -a + 网络参数设置
- HttpURLConnection的封装以及Callback的使用
- 浅谈多进程多线程的选择
- 网络编程总结TCP、UDP、URL编程