I want to upload a file and get the post data in my page.
With usual form it works fine:
<form id="formulario" action="nextPage" method="post" enctype="multipart/form-data">
<input type="file" name="aux.urlFile" id="InputDocumento" value =""></input>
</form>
In "nextPage" I can see the post value is
aux.urlFile UPLOADEDFILES*fileDefault#0d08abdfdfcc90f6461fff25236e_aux_urlFile_data_cdata2_psf_B46A0E4F94194001404ED107*data_cdata2.psf*application/octet-stream
Now, I want to do it without reload the page:
<form id="formulario" action="" method="post" enctype="multipart/form-data">
<input type="file" name="aux.urlFile" id="InputDocumento" value ="">
</input>
JQuery:
$(document).on('submit','#formulario',function(){
event.preventDefault();
var formData = new FormData($(this)[0]);
for (var [key, value] of formData.entries()) {
console.log(key, value);
}
$.ajax({
type: "POST",
data: formData,
processData : false,
success:function (data) {
debugger;
},
error: function (jXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
});
In console:
aux.urlFile
FilelastModified: 1482486542000
lastModifiedDate: Fri Dec 23 2016 10:49:02 GMT+0100 (Romance Standard Time)
name: "1.psf"
size: 1675type: "
"webkitRelativePath: "
"__proto__: File
And in success only the html code in my page. How can I get the post value and check if the file is uploaded?