Last active
January 26, 2016 14:22
-
-
Save amirnissim/6129588 to your computer and use it in GitHub Desktop.
XHR
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
var resource = "http://my-service/data.json"; | |
var xhr = new XMLHttpRequest(); | |
xhr.onprogress = updateProgress; | |
xhr.onreadystatechange = updateReadyState; | |
xhr.open('GET', resource, true); | |
xhr.send(); | |
function updateProgress (e) { | |
if (e.lengthComputable){ | |
var progress = Math.round((e.loaded / e.total) * 100); | |
console.log(progress + "%"); | |
} | |
} | |
function updateReadyState(e) { | |
if (xhr.readyState === 4) { | |
alert("done"); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment