progress ajax request

Solutions on MaxInterview for progress ajax request by the best coders in the world

showing results for - "progress ajax request"
Élisabeth
05 Nov 2018
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});