0
I would like to know how to send my <input type="file">
to the php
through the ajax
. I wrote the code but the same does not call the url
php
and does not return me error.
html code:
<button class="icon-overlay">Pesquisar Img</button>
<form id="imgUpload" enctype="multipart/form-data">
<input type="file" id="avatar-img" name="file" accept="image/jpeg" style="display: none;">
</form>
jquery code:
$(".icon-overlay").click(function(){
self.executar();
});
$('input:file').change(function() {
$('#imgUpload').submit(function() {
var formulario = document.getElementById('imgUpload');
var formData = new FormData(formulario);
$.ajax({
url: "controller/trade-photo.php",
type: "POST",
data: formData,
dataType: 'json',
processData: false,
contentType: false,
success: function(retorno){
alert(retorno);
}
});
return false;
});
});
function executar(){
$("#avatar-img").click();
}
Possible duplicate of Image upload with Jquery
– Sveen