大家有必要看到文末
xhr传统的AJAX传输对象,在做后台系统的时候经常遇到文件上传的情景,以往的xhr已经能够应对文件表格上传的功能,但如今遇到项目需求,上传的文件比较大数据表较多,为了提高用户体验有必要增加文件上传进度条,让用户知悉当前的操作进度,以免一直停留在空白页究竟有没有上传服务器都不清楚。此文用到的也还是AJAX的技术,XMLHttpRequest Level 2特性(也是老东西)
XHR2的事件例表:
attribute type Explanation onloadstart
loadstart
When the request starts. onprogress
progress
While loading and sending data. onabort
abort
When the request has been aborted, either by invoking the abort()
method or navigating away from the page.onerror
error
When the request has failed. onload
load
When the request has successfully completed. ontimeout
timeout
When the author specified timeout has passed before the request could complete. onloadend
loadend
When the request has completed, regardless of whether or not it was successful.
回顾AJAX基本知识
此文要做进度条,必须要在xhr.readyState === 3(解析,XMLHttpRequest对象开始持续读取服务器的响应)的状态中进行获取进度
<