Delete Using Php
ID Page Name Menu Position Published Added Action
0001 About us Header Menu Yes 15/07/2018 Delete
0002 Our Vision Header Menu Yes 15/07/2018 Delete
0003 Team Footer Menu Yes 15/07/2018 Delete
0004 Our Documents Header Menu No 15/07/2018 Delete
0005 Why us? Footer Menu No 15/07/2018 Delete
Source Code
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
$('.btn-danger').on('click', function() {
  var type = $(this).data('type');
  var data = $(this).data("set");
  var parent = $(this).parent().parent();
  if (type === 'delete') {
    swal({
      title: data.title + ' Delete',
      text: '"' + data.name + '" are you sure you want to delete?',
      type: 'warning',
      showCancelButton: true,
      confirmButtonColor: '#3085d6',
      cancelButtonColor: '#d33',
      cancelButtonText: 'Cancel',
      confirmButtonText: 'Delete',
      confirmButtonClass: 'btn btn-space btn-lg btn-success hover',
      cancelButtonClass: 'btn btn-space btn-lg btn-danger hover',
      buttonsStyling: false,
      preConfirm: function() {
        return new Promise(function(resolve) {
          $.ajax({
            url: 'php/controller.php',
            /* php post url */
            type: 'POST',
            data: {
              id: data.id,
              delete: data.option,
              extra: data.extra ? data.extra : null,
              title: encodeURIComponent(data.name)
            },
            dataType: 'html'
          }).done(function(response) {
            swal({
              title: 'Deleted!',
              text: data.title + ' successfully deleted.',
              type: 'success',
              confirmButtonClass: 'btn btn-space btn-lg btn-primary hover',
              confirmButtonText: 'Ok',
              buttonsStyling: false
            });
            parent.fadeOut(400, function() {
              parent.remove();
            });
            $('html, body').animate({
              scrollTop: 0
            }, 600);
          }).fail(function() {
            swal({
              title: 'An error occurred',
              text: 'Please try again later :)',
              type: 'error',
              confirmButtonClass: 'btn btn-primary btn-lg',
              buttonsStyling: false
            });
          });
        });
      },
      allowOutsideClick: false
    });
  }
});