Advertisement
cdsatrian

AJaX progress

Feb 21st, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $.ajax({
  2.     xhr: function() {
  3.         var xhr = new window.XMLHttpRequest();
  4.         xhr.upload.addEventListener("progress", function(evt) {
  5.             if (evt.lengthComputable) {
  6.                 var percentComplete = evt.loaded / evt.total;
  7.                 //Do something with upload progress here
  8.             }
  9.        }, false);
  10.  
  11.        xhr.addEventListener("progress", function(evt) {
  12.            if (evt.lengthComputable) {
  13.                var percentComplete = evt.loaded / evt.total;
  14.                //Do something with download progress
  15.            }
  16.        }, false);
  17.  
  18.        return xhr;
  19.     },
  20.     type: 'POST',
  21.     url: "/",
  22.     data: {},
  23.     success: function(data){
  24.         //Do something on success
  25.     }
  26. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement