I'd like to know how to send my <input type="file">
to php
through ajax
. I wrote the code but it does not call url
php
and it does not return 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();
}