Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 11, 2021 00:00
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/35e46b7a5edaa56abab9b0b18d315652 to your computer and use it in GitHub Desktop.
Save parzibyte/35e46b7a5edaa56abab9b0b18d315652 to your computer and use it in GitHub Desktop.
/*
En el clic del botón hacemos una petición a ./tomar_foto_guardar
*/
const $btnTomarFotoServidor = document.querySelector("#btnTomarFotoServidor"),
$estado = document.querySelector("#estado");
$btnTomarFotoServidor.onclick = async () => {
$estado.textContent = "Tomando foto...";
const respuestaRaw = await fetch("./tomar_foto_guardar");
const respuesta = await respuestaRaw.json();
let mensaje = "";
if (respuesta.ok) {
mensaje = `Foto guardada como ${respuesta.nombre_foto}`;
} else {
mensaje = `Error tomando foto`;
}
$estado.textContent = mensaje;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment