i have a code where i am trying to call aweetalert, note it is using sweetalert, not sweetAlert2.
So here is the code
JS Code
function showMessage() {
swal({
title: "",
html: 'Update <b>data.</b>',
type: "warning",
showCancelButton: true,
confirmButtonColor: "##EF5350",
confirmButtonText: "Yes, Proceed",
cancelButtonText: "Cancel",
reverseButtons: true
},function(isConfirmed) {
alert(isConfirmed)
if (isConfirmed) {
alert($(".openStandings").attr('data-href'));
$.ajax({
type: "POST",
url: $(".openStandings").attr('data-href'),
success: function(data) {
alert(data);
if (data.toLowerCase().indexOf("error") >= 0) {
swal({
title: "Oops",
text: data,
type: "error",
showCancelButton: false,
confirmButtonColor: "##EF5350",
confirmButtonText: "OK",
closeOnConfirm: true
});
} else {
swal({
title: "Great",
text: data,
type: "success",
showCancelButton: false,
confirmButtonColor: "##EF5350",
confirmButtonText: "OK",
closeOnConfirm: true
});
}
}
})
}
})
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
<button onclick="showMessage()" class="openStandings" data-href="page.cfm">Click Me<button>
the ptoblem is first swal works, but when it goes into callback, nothing happens
SWAL is promise-based; it doesn't directly accept a callback. You can use
.then()instead: