Created
May 14, 2014 18:50
-
-
Save AngeloMerlo/901baf110d515dadefea to your computer and use it in GitHub Desktop.
DRY - Ajax usando jQuery e enviando arquivo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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