Skip to content

Instantly share code, notes, and snippets.

@Cheslab
Last active March 25, 2018 20:45
Show Gist options
  • Save Cheslab/5db6f7690e6f5ddebc5d9433d6186edb to your computer and use it in GitHub Desktop.
Save Cheslab/5db6f7690e6f5ddebc5d9433d6186edb to your computer and use it in GitHub Desktop.
SweetAlert confirmation window + ajax
// SweetAlert.js is required
$('.trigger').click(function(e) {
e.preventDefault();
swal({
title: "Are you sure?",
text: "If you're sure click YES",
icon: "warning",
buttons: true,
dangerMode: true
}).then(function(confirmed) {
if (confirmed) {
$.ajax({
type: "POST",
url: "script/to/execute.php",
success: function(response) {
if (response == 'ok') {
swal("Done!", {
icon: "success"
});
} else {
swal("Sorry, couldn't do this", {
icon: "error"
});
}
},
error: function() {
swal("Something went worng!", {
icon: "error"
});
}
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment