惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Commits to openclaw:main
Recent Commits to openclaw:main
U
Unit 42
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
Martin Fowler
Martin Fowler
人人都是产品经理
人人都是产品经理
Microsoft Security Blog
Microsoft Security Blog
T
The Blog of Author Tim Ferriss
博客园 - Franky
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Palo Alto Networks Blog
NISL@THU
NISL@THU
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
J
Java Code Geeks
Google DeepMind News
Google DeepMind News
C
Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Spread Privacy
Spread Privacy
小众软件
小众软件
T
Threat Research - Cisco Blogs
Project Zero
Project Zero
博客园 - 三生石上(FineUI控件)
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Register - Security
The Register - Security
The Hacker News
The Hacker News
F
Fortinet All Blogs
Security Latest
Security Latest
Cisco Talos Blog
Cisco Talos Blog
The GitHub Blog
The GitHub Blog
Stack Overflow Blog
Stack Overflow Blog
T
The Exploit Database - CXSecurity.com
量子位
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
G
GRAHAM CLULEY
D
DataBreaches.Net
P
Privacy International News Feed
Y
Y Combinator Blog
Simon Willison's Weblog
Simon Willison's Weblog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
P
Proofpoint News Feed

博客园 - 灌木大叔

win10LTCS2021下载激活 程序员在线工具 宽带、IPTV及语音共享同一根网线传输原理 NFS与iSCSI Target性能比较 VMware vSphere安装 java解析html的table元素 chrome插件脚本background_script和content_script chrome跨域设置 Proxmox Virtual Environment(简称PVE)介绍 openwrt(LEDE)路由器简单设置 无损压缩FLAC,APE与WAV 创新的出路 走进作坊 团队--动物世界 vs2010+转换到 COFF 期间失败 windows删除用户时用户不属于此组 word无法创建工作文件,IE打开网页很慢 linux进程VIRT虚拟内存数值高 Java命令如何编译项目 UML(统一建模语言)应用 UML(统一建模语言)类关系
html5ajax上 传文件代码
灌木大叔 · 2023-03-14 · via 博客园 - 灌木大叔

html5上传文件api

使用XMLHttpRequest上传文件
var xhr = new XMLHttpRequest();

//监听选择文件信息

function fileSelected() {

//HTML5文件API操作

var file = document.getElementById('fileName').files[0];

if (file) {

var fileSize = 0;

if (file.size > 1024 * 1024)

fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';

else

fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';

document.getElementById('fileName').innerHTML = 'Name: ' + file.name;

document.getElementById('fileSize').innerHTML = 'Size: ' + fileSize;

document.getElementById('fileType').innerHTML = 'Type: ' + file.type;

}

}

//上传文件

function uploadFile() {

var fd = new FormData();

//关联表单数据,可以是自定义参数

fd.append("name", document.getElementById('name').value);

fd.append("fileName", document.getElementById('fileName').files[0]);

//监听事件

xhr.upload.addEventListener("progress", uploadProgress, false);

xhr.addEventListener("load", uploadComplete, false);

xhr.addEventListener("error", uploadFailed, false);

xhr.addEventListener("abort", uploadCanceled, false);

//发送文件和表单自定义参数

xhr.open("POST", "/user/uploadifyTest_doUpload");

xhr.send(fd);

}

//取消上传

function cancleUploadFile(){

xhr.abort();
xhr.abort();

}

//上传进度

function uploadProgress(evt) {

if (evt.lengthComputable) {

var percentComplete = Math.round(evt.loaded * 100 / evt.total);

document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';

}

else {

document.getElementById('progressNumber').innerHTML = 'unable to compute';

}

}

//上传成功响应

function uploadComplete(evt) {

//服务断接收完文件返回的结果

alert(evt.target.responseText);

}

//上传失败

function uploadFailed(evt) {

alert("上传失败");

}

//取消上传

function uploadCanceled(evt) {

alert("您取消了本次上传.");

}