Skip to content

Instantly share code, notes, and snippets.

@amirnissim
Last active January 26, 2016 14:22
Show Gist options
  • Save amirnissim/6129588 to your computer and use it in GitHub Desktop.
Save amirnissim/6129588 to your computer and use it in GitHub Desktop.
XHR
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