Skip to main content

How to use sweet alert (Trash Sweet Alert) before redirect link?

 <button type="btn" class="btn_cancel deleteOnElement" type="button" data-route="{{ route('cancel-order', $order_id) }}">Cancel</button>


<!-- sweet alert -->

 <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>


<script type="text/javascript">

//end application user type

$(document).on('click','.deleteOnElement', function(event)

{

      var route  = $(this).data('route');

      //alert(route);

      swal({

        title: "Confirm Trash",

        text: "Are you sure you want to cancel this request? ",

        icon: "warning",

        buttons: true,

        dangerMode: true,

      })

      .then((willDelete) => {

        if (willDelete) {

          window.location.replace(route);

        } else {

          swal("Your data is safe!");

        }

      });          

});

</script>

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...