Skip to content

Instantly share code, notes, and snippets.

@gregory-yet
Created February 15, 2018 15: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 gregory-yet/339e2bd0b244a2f43ede8c397e2d7e45 to your computer and use it in GitHub Desktop.
Save gregory-yet/339e2bd0b244a2f43ede8c397e2d7e45 to your computer and use it in GitHub Desktop.
SweetAlert Confirmation with Ajax
$(document).ready(function(){
$('a#delete').on('click', function(){
var $id = $(this).data('id');
swal({
title: 'Êtes-vous sur ?',
text: "Cette action est irréversible.",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#d33',
cancelButtonColor: '#3085d6',
reverseButtons: true,
confirmButtonText: 'Supprimer',
cancelButtonText: 'Annuler'
}).then((result) => {
if (result.value) {
$.post(siteUrl + '/admin/deleteUser', {id: $id})
.done(function(data){
if(data['code'] == 0){
$('tr[data-user="'+$id+'"]').fadeOut('slow', function(){$(this).remove()});
return swal('Succès', "L'utilisateur a bien été supprimé", "success");
}
else {
return swal('Erreur', data['message'], "error");
}
})
.fail(function(){
swal('Erreur', 'Une erreur inconnue est survenue', 'error');
});
}
})
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment