Skip to content

Instantly share code, notes, and snippets.

@AngeloMerlo
Created May 14, 2014 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AngeloMerlo/901baf110d515dadefea to your computer and use it in GitHub Desktop.
Save AngeloMerlo/901baf110d515dadefea to your computer and use it in GitHub Desktop.
DRY - Ajax usando jQuery e enviando arquivo
// Não repita a si mesmo - Ajax usando jQuery e enviando input type file
// ----------------------------------------------------------------------
var formData = new FormData($('form')[0]); // Cria o objeto com os dados do formulário
$('input').click(function(){
$.ajax({
url : 'controle.php',
type : 'post',
data : formData, // Variável que contem o objeto a ser enviado
processData: false, // Parte da mágica para o envio do arquivo
contentType: false, // Parte da mágica para o envio do arquivo
beforeSend: function(){
$('#carregando').fadeIn();
},
timeout: 3000,
success: function(retorno){
$('#resposta').html(retorno);
},
error: function(erro){
$('#resposta').html(erro);
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment