JavaScript, jQuery wiele żądań AJAX jednocześnie

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 >= length) {
                clearInterval(calling);
            }
        }, 2000); // Delay is for testing. Normaly there is no delay
}

Próbuję przesłać plik jeden po drugim. Ale problem polega na tym, że żądanie wysyłania ajax poprawnie, ale uzyskanie tylko jednego (pierwszego) powrotu danych.

Moim celem jest stworzenie skryptu, który przesyła obrazy (a później inne pliki) na zmianę wejścia [typ = plik]. Próbowałem przesłać wiele plików z jednym żądaniem, ale postępował rejestrowanie ich jako jedno. Miałem pomysł, aby pociąć (podzielić) pliki na części i wysłać je, ale ten wariant wydaje się łatwiejszy (wystarczy, aby działał, a potem go ulepszam). Dzięki.

questionAnswers(1)

yourAnswerToTheQuestion