Last active
September 11, 2018 10:02
-
-
Save JokingChicken/25eacc24f7d8fe5a3c09ca506a6f3dba to your computer and use it in GitHub Desktop.
When uploading something get the procentage
This file contains 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
<script> | |
/*usage: | |
request("get", "https://github.com/DanBrothers/danbrothers.github.io/blob/master/js/main.js", null, | |
function(status, data) { | |
if(status==="percent") { | |
console.log("file progress: " + data + "%"); | |
} | |
if(...) { | |
} | |
} | |
); | |
*/ | |
function request(method, url, data, cb) { | |
var ajax = new XMLHttpRequest(); | |
ajax.addEventListener("progress", function go(event) {cb("percent", ((event.loaded / event.total) * 100))}, false); | |
ajax.addEventListener("load", function go(event) {cb("eventloaded")}, false); | |
ajax.addEventListener("error", function go(event) {cb("error")}, false); | |
ajax.addEventListener("abort", function go(event) {cb("aborted")}, false); | |
ajax.open(method, url, true); | |
ajax.send(data); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment