Can I send FormData not through ajax?

UPD 1 Interested in the ability to submit a form with a page reload. And there are files in FormData, so FormData is used

UPD 2 Code for explanation https://jsfiddle.net/temoffey/q0g8tusf/1/

var send_form = document.getElementById('send_form'); var file_input = document.getElementById('file_input'); var file_view = document.getElementById('file_view'); var file_list = []; file_input.addEventListener('change', function() { for (i=0;i<this.files.length;i++) { file_list.push(this.files[i]); } file_view.innerText = ''; for (i in file_list) { file_view.innerHTML = file_view.innerHTML + file_list[i].name + '<br />'; } }); send_form.addEventListener('submit', function() { var form_data = new FormData(); form_data.append('documents[]', file_list); // Что нужно, что бы form_data был отправлен? }); 
 <form id="send_form" enctype="multipart/form-data" method="post"> <input type="file" id="file_input" multiple /> <br /> <br /> <div id="file_view"></div> <br /> <input type="submit" /> </form> 

  • And what you do not like the native form submission? She, too, according to the idea of ​​the forms. Date sent and with a reboot, just specify the action in the form - ThisMan
  • With native submission, you cannot select files from multiple folders. When you select a second time, the files selected at the first are detached. - temoffey

1 answer 1

Here is a great example here :

 var formData = new FormData(); formData.append("username", "Groucho"); formData.append("accountnum", 123456); formData.append("userfile", fileInputElement.files[0]); var content = '<a id="a"><b id="b">hey!</b></a>'; var blob = new Blob([content], { type: "text/xml"}); formData.append("webmasterfile", blob); var request = new XMLHttpRequest(); request.open("POST", "http://foo.com/submitform.php"); request.send(formData); 
  • But you need to send was not through Ajax - temoffey