1$.ajax({
2 url: path,
3 type: 'post',
4 data: {payload: payload},
5 xhr: function () {
6 var xhr = $.ajaxSettings.xhr();
7 xhr.onprogress = function e() {
8 // For downloads
9 if (e.lengthComputable) {
10 console.log(e.loaded / e.total);
11 }
12 };
13 xhr.upload.onprogress = function (e) {
14 // For uploads
15 if (e.lengthComputable) {
16 console.log(e.loaded / e.total);
17 }
18 };
19 return xhr;
20 }
21}).done(function (e) {
22 // Do something
23}).fail(function (e) {
24 // Do something
25});