-
HTML5 jQuery+FormData 异步上传文件,带进度条
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <link href="../resources/css/common.css" rel="stylesheet" />
- <script src="../resources/js/jquery-2.1.4.js"></script>
-
- </head>
-
- <body>
- <h2>HTML5异步上传文件,带进度条</h2>
- <form method="post" enctype="multipart/form-data">
- 其他需要提交的信息:<input type="text" name="otherInfo"/><br/><br/>
- 选择要上传的文件:<br/>
- <input type="file" name="file" /><span></span><br/>
- <input type="file" name="file" /><span></span><br/>
- </form>
-
- <br/><br/>
- <input type="button" value="上传吧" onclick="upload()"/>
- <br/><br/>
- 上传进度:<progress></progress><br/>
- <p id="progress">0 bytes</p>
- <p id="info"></p>
- </body>
- <script>
- var totalSize = 0;
- $(':file').change(function() {
- var file = this.files[0];
- name = file.name;
- size = file.size;
- type = file.type;
- url = window.URL.createObjectURL(file);
- $(this).next().html("文件名:" + name + " 文件类型:" + type + " 文件大小:" + size + " url: " + url);
- totalSize += size;
- $("#info").html("总大小: " + totalSize + "bytes");
- });
- function upload() {
- var formData = new FormData($('form')[0]);
- $.ajax({
- url: "http://localhost:8080/MyJavaStudio/servlet/file/upload",
- type: "POST",
- data: formData,
- xhr: function(){
- myXhr = $.ajaxSettings.xhr();
- if(myXhr.upload){
- myXhr.upload.addEventListener('progress',progressHandlingFunction, false);
- }
- return myXhr;
- },
- success: function(result){
- $("#result").html(result.data);
- },
- contentType: false,
- processData: false
- });
- }
- function progressHandlingFunction(e) {
- if (e.lengthComputable) {
- $('progress').attr({value : e.loaded, max : e.total});
- var percent = e.loaded/e.total*100;
- $('#progress').html(e.loaded + "/" + e.total+" bytes. " + percent.toFixed(2) + "%");
- }
- }
- </script>
- </html>
-
相关阅读:
Unity3D保护资源管理文件的AssetBundle包加密!
untiy Kinect SDK 的默认BUG 修改方法
Android 插件扩展系列之 封装与应用
datagridview 单击单元格获取单元格的内容
winform 显示动态图片 Gif
Unity 漫游相机脚本
Unity3D教程:c#脚本yield的用法
Unity 脚本实现CoverFlow效果
删除 treeview Node节点 循环删除子节点 存储过程
Unity 怪物AI
-
原文地址:https://www.cnblogs.com/tyqing/p/5995538.html
Copyright © 2020-2023
润新知