how can i upload files asynchronously

Solutions on MaxInterview for how can i upload files asynchronously by the best coders in the world

showing results for - "how can i upload files asynchronously"
Mahe
01 Jan 2017
1$(':button').on('click', function () {
2  $.ajax({
3    // Your server script to process the upload
4    url: 'upload.php',
5    type: 'POST',
6
7    // Form data
8    data: new FormData($('form')[0]),
9
10    // Tell jQuery not to process data or worry about content-type
11    // You *must* include these options!
12    cache: false,
13    contentType: false,
14    processData: false,
15
16    // Custom XMLHttpRequest
17    xhr: function () {
18      var myXhr = $.ajaxSettings.xhr();
19      if (myXhr.upload) {
20        // For handling the progress of the upload
21        myXhr.upload.addEventListener('progress', function (e) {
22          if (e.lengthComputable) {
23            $('progress').attr({
24              value: e.loaded,
25              max: e.total,
26            });
27          }
28        }, false);
29      }
30      return myXhr;
31    }
32  });
33});