Как я могу отменить подтверждение сладкого оповещения - PullRequest
0 голосов
/ 26 сентября 2019

Привет. Я использую «сладкое оповещение» для удаления товара с моего веб-сайта. Я хочу использовать его с двумя вариантами: сначала «ОК», а затем «Отмена»

, но когда я нажимаю в любом месте на страницекнопка удаления и отмены не работает

вот мой код

 $(document).on('click', '#removeCat', function(e) {
    e.preventDefault();
    var id = $(this).data('id');
    swal({
        title: "are u sure?",
        type: "error",
        confirmButtonClass: "btn-danger",
        confirmButtonText: "ok",
        cancelButtonText: "cancel",
        showCancelButton: true,
    })
    .then(function() {
    $.ajax({
        type: "post",
        url: "{{url('dashboard/shop/product-category/delete')}}",
        data: {
            id: id,
            "_token": $('#csrf-token')[0].content //pass the CSRF_TOKEN()
        },
        success: function(data) {
            var url = document.location.origin + "/dashboard/shop/product-category";
            location.href = url;
        }
    });
});

});

1 Ответ

1 голос
/ 26 сентября 2019

Вот решение:

swal({
  title: "Are you sure?",
  text: "You will not be able to recover this imaginary file!",
  type: "warning",
  showCancelButton: true,
  confirmButtonClass: "btn-danger",
  confirmButtonText: "Yes, delete it!",
  cancelButtonText: "No, cancel plx!",
  closeOnConfirm: false,
  closeOnCancel: false
},
function(isConfirm) {
  if (isConfirm) {
    $.ajax({
        type: "post",
        url: "{{url('dashboard/shop/product-category/delete')}}",
        data: {
            id: id,
            "_token": $('#csrf-token')[0].content //pass the CSRF_TOKEN()
        },
        success: function(data) {
            var url = document.location.origin + "/dashboard/shop/product-category";
            location.href = url;
        }
    });
  } else {
    swal("Cancelled", "Your imaginary file is safe :)", "error");
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.css" integrity="sha256-Z8TW+REiUm9zSQMGZH4bfZi52VJgMqETCbPFlGRB1P8=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.min.css" integrity="sha256-zuyRv+YsWwh1XR5tsrZ7VCfGqUmmPmqBjIvJgQWoSDo=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.js" integrity="sha256-ZvMf9li0M5GGriGUEKn1g6lLwnj5u+ENqCbLM5ItjQ0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.min.js" integrity="sha256-JirYRqbf+qzfqVtEE4GETyHlAbiCpC005yBTa4rj6xg=" crossorigin="anonymous"></script>
...