Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created January 17, 2021 22:14
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/57aec9b7382a441c486fc2647fed98b3 to your computer and use it in GitHub Desktop.
Save parzibyte/57aec9b7382a441c486fc2647fed98b3 to your computer and use it in GitHub Desktop.
const respuestaConfirmacion = await Swal.fire({
title: "Confirmación",
text: "¿Eliminar el producto? esto no se puede deshacer",
icon: 'warning',
showCancelButton: true,
cancelButtonColor: '#3085d6',
confirmButtonColor: '#d33',
confirmButtonText: 'Sí, eliminar',
cancelButtonText: 'Cancelar',
});
if (respuestaConfirmacion.value) {
const url = `./eliminar_producto.php?id=${idProducto}`;
const respuestaRaw = await fetch(url, {
method: "DELETE",
});
const respuesta = await respuestaRaw.json();
if (respuesta) {
Swal.fire({
icon: "success",
text: "Producto eliminado",
timer: 700, // <- Ocultar dentro de 0.7 segundos
});
} else {
Swal.fire({
icon: "error",
text: "El servidor no respondió con una respuesta exitosa",
});
}
// De cualquier modo, volver a obtener los productos para refrescar la tabla
obtenerProductos();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment