Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active April 20, 2018 22:25
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 parzibyte/8eb42dd5218d8d214825f1ad2348de36 to your computer and use it in GitHub Desktop.
Save parzibyte/8eb42dd5218d8d214825f1ad2348de36 to your computer and use it in GitHub Desktop.
$(function() {
var $fotoAlumno = $("#fotoAlumno"),
$btnGuardar = $("#guardarImagen");
$btnGuardar.click(function() {
var archivos = $fotoAlumno[0].files;
if (archivos.length > 0) {
var foto = archivos[0]; //Sólo queremos la primera imagen, ya que el usuario pudo seleccionar más
var lector = new FileReader();
//Ojo: En este caso 'foto' será el nombre con el que recibiremos el archivo en el servidor
formData.append('foto', foto);
$.ajax({
url: "htpp://localhost/la/ruta/de/nuestro/controlador",
data: formData,
type: 'POST',
contentType: false,
processData: false,
success: function(resultados) {
console.log("Petición terminada. Resultados", resultados);
}
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment