Created
December 12, 2015 12:27
-
-
Save xiangst0816/2cd901492527cd4d5b25 to your computer and use it in GitHub Desktop.
监听进度变化,计算进度相关。From http://javascript.ruanyifeng.com/dom/event.html#toc1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var xhr = new XMLHttpRequest(); | |
| xhr.addEventListener("progress", updateProgress, false); | |
| xhr.addEventListener("load", transferComplete, false); | |
| xhr.addEventListener("error", transferFailed, false); | |
| xhr.addEventListener("abort", transferCanceled, false); | |
| xhr.open(); | |
| function updateProgress (e) { | |
| if (e.lengthComputable) { | |
| var percentComplete = e.loaded / e.total; | |
| } else { | |
| console.log('不能计算进度'); | |
| } | |
| } | |
| function transferComplete(e) { | |
| console.log('传输结束'); | |
| } | |
| function transferFailed(evt) { | |
| console.log('传输过程中发生错误'); | |
| } | |
| function transferCanceled(evt) { | |
| console.log('用户取消了传输'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment