2
I need to upload without leaving the page, I believe the best would be ajax, correct?
I found some post here on Sopt, but I could not adapt my need.
I need to send these two fields, one of file and the other of 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;
}
});
});
How to do as soon as the file is selected whatever, is sent via ajax including the hidden field?
I don’t want to use button, just select and send.
@Ivanferrer this topic mentioned was one of the ones I’ve seen, but in the tests I did I didn’t get any success.
– Tiago
Well, it’s very simple to do this, just follow this tutorial: http://www.devmedia.com.br/upload-de-imagens-sem-dar-refresh-utilizando-php-e-jquery/22190
– Ivan Ferrer
Here is another example: http://stackoverflow.com/questions/30932027/upload-multiple-files-with-ajax-and-jquery just change the method
$.each()
for the answer accepted.– Ivan Ferrer
It is not duplicate because there is a drag drop in what it asks.
– Lollipop
you want to send file using ajax?
– Marconi