28 June 2023

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>

No comments:

Post a Comment

How to create youtube videos slider with play and pause option in wordpress?

Create youtube videos slider with play and pause option in wordpress youtube videos slider Use this shortcode:- [punjab_today] function my_...