sweetalert 2 подтверждает невозможность отмены

#javascript #php

#javascript #php

Вопрос:

мне нужна помощь, чтобы решить мою проблему, у меня возникла проблема после нажатия кнопки отмены на sweetalert, чтобы сохранить успех, я хочу, чтобы, если я нажму «Отменить», это не увенчалось успехом и функция отмены, это мой код в href

 <a href="mahasiswa.php?hapus=<?=$tampil[idm]?>"  class="btn btn-danger shadow btn-xs sharp delete-link"><i class="fa fa-trash"></i></a>
  

это код на javascript

 <script type="text/javascript">
       jQuery(document).ready(function($){
            $('.delete-link').on('click',function(){
                var getLink = $(this).attr('href');
                swal({
                        title: 'Apakah kamu yakin? ',
                        text: "Anda tidak dapat mengembalikan ini!",
                        type: 'warning',
                        showCancelButton: true,
                        confirmButtonColor: '#4fa7f3',
                        cancelButtonColor: '#d57171',
                        confirmButtonText: 'Iya, hapus!',
                        }).then(function () {
                            swal(
                                'Terhapus!',
                                'Data telah dihapus.',
                                'success',
                                 window.location.href = getLink
                            )
                    });
                return false;
            });
        });
    </script>
  

надеюсь, вы, ребята, сможете мне помочь 🙂

Ответ №1:

Я решаю свою проблему

 Swal.fire({
    title: 'Apakah kamu yakin? ',
    text: "Anda tidak dapat mengembalikan ini!",
    icon: 'warning',
    showCancelButton: true,
    confirmButtonColor: '#4fa7f3',
    cancelButtonColor: '#d57171',
    confirmButtonText: 'Iya, hapus!',
    cancelButtonText: 'Batal'
    }).then(function (result) {
          if (result.isConfirmed) {
            Swal.fire(
              'Terhapus!',
              'Data berhasil terhapus.',
              'success',
              window.location.href = getLink
            )
          } else if (
            result.dismiss === Swal.DismissReason.cancel
          ) {
            Swal.fire(
              'Batal',
              'Data tidak terhapus.',
              'error'
            )
          }
});