I only get the last file downloaded from the form submit()
, whereas I expect multiple files to be downloaded using the for
loop. I'm pretty new to JavaScript and jQuery. Please help.
I'm sending a request to a certain Web API URL (WEBAPIURL
) which takes a token (TOKEN
) for authentication and a file reference number (fileId
). I've provided all of the parameters correctly. I can download each individual file but cannot download multiple files when sending them through a for
loop. Only the last file is downloaded.
for(id in fileIDs){
var form = $('<form></form>').attr('action', WEBAPIURL).attr('method', 'post');
form.append($('<input></input>').attr('type', 'hidden').attr('name', "token").attr('value', TOKEN));
form.append($('<input></input>').attr('type', 'hidden').attr('name', "fileId").attr('value', fileIDs[id]));
form.appendTo('body').submit().remove();
}