title: Javascript, jQuery multiple AJAX requests at same time
body: <pre><code>function makeCall(file, handlerFile, sendMethod, formData) {
      //console.log(instance.files);
  
      $.ajax({
          url: handlerFile,
          type: sendMethod,
          xhr: function() {  // Custom XMLHttpRequest
              var xhr = $.ajaxSettings.xhr();
  
              if(xhr.upload) { // Check if upload property exists
                  xhr.upload.addEventListener('progress', progressHandlingFunction.bind(file)); // For handling the progress of the upload
                  //xhr.upload.addEventListener('loadend', successHandler.bind(xhr));
              }
  
              //console.log(xhr);
  
              return xhr;
          },
          beforeSend: beforeSendHandler.bind(file),
          success: completeHandler.bind(file),
          //error: errorHandler,
          data: formData, // Form data
          dataType: 'json',
          cache: true,
          //async: false,
          contentType: false,
          processData: false
      });
  
  }
  
  
  
  $(".afu-input").on('change', function() {
          var i = 0;
          var length = this.files.length;
          var files = this.files;
  
          var calling = setInterval(function() {
              var file = files[i];
              console.log(file);
  
              uid  = generateUniqueId();
              file.id = uid;
  
              var formData = null;
              formData = new FormData();
  
              formData.append(i, file);
              formData.append(i, [uid]);
  
              makeCall(file, handlerFile, sendMethod, formData);
  
              i++;
  
              if (i &gt;= length) {
                  clearInterval(calling);
              }
          }, 2000); // Delay is for testing. Normaly there is no delay
  }
  </code></pre>
  
  <p>I'm trying to upload file one by one. But the problem is that ajax sending request properly, but getting only one(first) data return.</p>
  
  <p>My goal is to create script which uploads images(and later other files) on input[type=file] change. I tried to upload multiple files with one request, but progress event registering them as one. I had idea to slice(chunk) files into pieces ant send them, but this variant seems easier(just need to make it work, then I improve it). Thanks.</p>