Skip to content

Instantly share code, notes, and snippets.

@lohic
Last active August 29, 2015 14:02
Show Gist options
  • Save lohic/adfa7f8e53869a0deee0 to your computer and use it in GitHub Desktop.
Save lohic/adfa7f8e53869a0deee0 to your computer and use it in GitHub Desktop.
ajax progress bar
// http://www.dave-bond.com/blog/2010/01/JQuery-ajax-progress-HMTL5/
$.ajax({
xhr: function()
{
var xhr = new window.XMLHttpRequest();
//Upload progress
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
//Do something with upload progress
console.log(percentComplete);
}
}, false);
//Download progress
xhr.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
//Do something with download progress
console.log(percentComplete);
}
}, false);
return xhr;
},
type: 'POST',
url: "/",
data: {},
success: function(data){
//Do something success-ish
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment