AJAX Download multiple files in parallel

There is this function:

function uploadFile(f, parent) { var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", function (event) { uploadProgress(event, parent); }, false); xhr.upload.addEventListener("load", function (event) { uploadComplete(event, parent); }, false); xhr.upload.addEventListener("error", uploadFailed, false); xhr.upload.addEventListener("abort", uploadCanceled, false); xhr.open("POST", "Upload.aspx", true); //xhr.setRequestHeader("Cache-Control", "no-cache"); xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); xhr.setRequestHeader("Content-Type", "multipart/form-data"); xhr.setRequestHeader("X-File-Name", f.name); xhr.setRequestHeader("X-File-Size", f.fileSize); xhr.send(f); } 

The "f" parameter of the function is the File that appears in the drop event (event.dataTransfer.files [0]) The problem is that I have several elements that trigger the drop event (and the uploadFile function is implicitly called), but the download does not performed in parallel. First, the first fallen file is downloaded, and after the download is complete, only then the second file is downloaded. Why are files not loading in parallel?

Thanks!

+4
source share
1 answer

This is done using the client side of the script, which by definition is single-threaded - one at a time in nature.

+1
source

Source: https://habr.com/ru/post/1381892/


All Articles