Как использовать Sweetalert при удалении строки в таблице - PullRequest
0 голосов
/ 29 апреля 2018

Я хочу использовать sweetalert, когда удаляю данные в таблице перед тем, как связать мой контроллер. Но он только вызывает мой контроллер и не показывает никаких предупреждений.

<a href="Table/Delete/<?php echo ($u->ID) ?>">
     <button id="a" type="button" class="btn btn-danger"> <i class="glyphicon glyphicon-trash"></i> Delete </button>
</a>

JS

<script>
   $('#a').on('click',function(event){
      event.preventDefault();
         swal({
            title: "Are you sure?",
            text: "Once deleted, you will not be able to recover this imaginary file!",
            icon: "warning",
            buttons: true,
            dangerMode: true,
         })
        .then((willDelete) => {
          if (willDelete) {
             swal("Poof! Your imaginary file has been deleted!", {
             icon: "success",
          });
          } else {
            swal("Your imaginary file is safe!");
            }
          });
   })
</script>

1 Ответ

0 голосов
/ 29 апреля 2018

не использовать <a href="..."> ссылка

HTML должен быть похож на ..

<div>
  <button id="a"></button>
</div>

JS должно быть похоже на

<script>
   $('#a').on('click',function(event){
      event.preventDefault();
         swal({
            title: "Are you sure?",
            text: "Once deleted, you will not be able to recover this imaginary file!",
            icon: "warning",
            buttons: true,
            dangerMode: true,
         })
        .then((willDelete) => {
          if (willDelete) {
             # delete row
             # show swal and redirect to your link
          } else {
            swal("Your imaginary file is safe!");
            }
          });
   })
</script>
...