如何在 post URL 之前表现出甜蜜的警觉

How to show sweeat alert before post the URL

我是第一次使用 sweeatalert。如何在 post URL 之前显示确认出汗警报。 我想在 post 和 URL 之前显示 sweeatalert。谢谢

<!--  -->
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<a href="<?=base_url();?>/method/post/<?= $data['id'] ?>" class="badge badge-danger float-right ml-1" onclick='return onButton();'>hapus</a>
<script>
    function onButton(){
       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>
<!--  -->
<link rel="stylesheet" type="text/css" href="http://192.168.2.40/Always_Fresh_Backend/backend/bower_components/sweetalert/css/sweetalert.css">

<script type="text/javascript" src="http://192.168.2.40/Always_Fresh_Backend/backend/bower_components/sweetalert/js/sweetalert.min.js"></script>

function sweetalert() {
 swal({
    title: "Are you sure?",
    text: "msg",
    type: "warning",
    showCancelButton: true,
    confirmButtonClass: "btn-danger",
    confirmButtonText: "Yes",
    closeOnConfirm: false
},
function(isConfirm){
    if (isConfirm) {
     $.ajax({
            url: "<?=BASEURL;?>/method/post/<?= $data['id'] ?>",
            type: "GET",
            beforeSend: function(){
            },
            complete: function(){
            },
            success: function (response) { 

            }
        });
    } else {

    }           

 function sweetalert() {
  swal({
   title: "Are you sure?",
   text: "msg",
   type: "warning",
   showCancelButton: true,
   confirmButtonClass: "btn-danger",
   confirmButtonText: "Yes",
   closeOnConfirm: false
  },
  function(isConfirm){
   if (isConfirm) {
    $.ajax({
     url: "link",
     type: "GET",
     beforeSend: function(){
     },
     complete: function(){
     },
     success: function (response) { 
      
     }
    });
   } else {
    
   }
   
  });
        
    }
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.min.js"></script>


<a href="#" class="badge badge-danger float-right ml-1" onclick='return sweetalert();'>hapus</a>