Last active
March 25, 2018 20:45
-
-
Save Cheslab/5db6f7690e6f5ddebc5d9433d6186edb to your computer and use it in GitHub Desktop.
SweetAlert confirmation window + ajax
This file contains hidden or 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
// 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