Advertisement
sanca

method delete

Jun 13th, 2022
2,401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.29 KB | None | 0 0
  1. $("#table-laporan").on("click", ".btn-delete", function () {
  2.         Swal.fire({
  3.             title: "Anda yakin?",
  4.             text: "Anda yakin ingin menghapus data?",
  5.             icon: "warning",
  6.             showCancelButton: true,
  7.             confirmButtonColor: "#3085d6",
  8.             cancelButtonColor: "#d33",
  9.             confirmButtonText: "Yes, delete it!",
  10.             allowOutsideClick: false,
  11.         }).then((result) => {
  12.             if (result.value) {
  13.                 Swal.fire({
  14.                     imageUrl: base_url + "/images/loading.png",
  15.                     imageHeight: 300,
  16.                     showConfirmButton: false,
  17.                     title: "Loading ...",
  18.                     allowOutsideClick: false,
  19.                 });
  20.  
  21.                 var idLaporan = $(this).data("id");
  22.                 var urlDelete =
  23.                     base_url + "/client/laporan/" + idLaporan + "/delete";
  24.                 $.ajax({
  25.                     url: urlDelete,
  26.                     type: "DELETE",
  27.                     contentType: false,
  28.                     processData: false,
  29.                     success: function (data) {
  30.                         Swal.fire({
  31.                             icon: "success",
  32.                             title: data.data.message,
  33.                             showConfirmButton: false,
  34.                             timer: 2000,
  35.                             allowOutsideClick: false,
  36.                         }).then(function () {
  37.                             refreshTable();
  38.                         });
  39.                     },
  40.                     error: function (jqXHR, textStatus, errorThrown) {
  41.                         var error = jqXHR.responseJSON;
  42.  
  43.                         if (error.meta) {
  44.                             var message = error.meta.message;
  45.                         } else {
  46.                             var message = error.message;
  47.                         }
  48.                         Swal.fire({
  49.                             icon: "error",
  50.                             title: message,
  51.                             showConfirmButton: false,
  52.                             timer: 2000,
  53.                             allowOutsideClick: false,
  54.                         });
  55.                     },
  56.                 });
  57.             }
  58.         });
  59.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement