Created
February 15, 2018 15:00
-
-
Save gregory-yet/339e2bd0b244a2f43ede8c397e2d7e45 to your computer and use it in GitHub Desktop.
SweetAlert Confirmation with Ajax
This file contains 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
$(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