I need to upload without leaving the page, I believe the best would be ajax, correct?
I found some posts here in SOpt, but I could not adapt my need.
I need to send these two fields, one for file and one for hidden text.
<input type="file" id="id-input-file-2" name="arquivo" class="form-control arquivo" />
<input type="hidden" name="onde" id="onde" value="cotacao">
.
$(".listaArquivo").click(function () {
var formData = new FormData(this);
var arquivo = $(".arquivo").val();
var onde = $("#onde").val();
$.ajax({
url: 'cotacoesEditarUpload.php',
type: 'POST',
data: formData,
success: function (data) {
alert(data)
},
cache: false,
contentType: false,
processData: false,
xhr: function() { // Custom XMLHttpRequest
var myXhr = $.ajaxSettings.xhr();
if (myXhr.upload) { // Avalia se tem suporte a propriedade upload
myXhr.upload.addEventListener('progress', function () {
/* faz alguma coisa durante o progresso do upload */
}, false);
}
return myXhr;
}
});
});
I do not want to use button, just select and send.