亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Sweetalert2 刪除確認

Sweetalert2 刪除確認

PHP
qq_遁去的一_1 2022-07-22 19:34:34
我想在 codeigniter 中使用 sweetalert2 進行刪除確認,但我不知道如何使它可以幫助我..?這是 sweetalert2 腳本      <script src="<?php echo base_url(); ?>sweetalert2/dist/sweetalert2.all.min.js"></script>      <script src="https://cdn.jsdelivr.net/npm/promise-polyfill"></script>      <script src="<?php echo base_url(); ?>sweetalert2/dist/sweetalert2.min.js"></script>      <link rel="stylesheet" href="<?php echo base_url(); ?>assets/sweetalert2/dist/sweetalert2.min.css">       <script type="text/javascript">      function hapus() {        event.preventDefault();       var form = event.target.form;       Swal.fire({      title: 'Are you sure?',      text: "You won't be able to revert this!",      icon: 'warning',      showCancelButton: true,      confirmButtonColor: '#3085d6',      cancelButtonColor: '#d33',      confirmButtonText: 'Yes, delete it!'    }).then((result) => {      if (result.value) {        Swal.fire(          'Deleted!',          'Your file has been deleted.',          'success'        )      }    })}    </script>這是刪除按鈕 <button onclick="hapus()" style="width:70px"type="button" class="btn btn-block btn-outline-danger"><?php echo anchor('postingan/hapus/'.$b->id,'Hapus');  ?></button>這是控制器function hapus($id){        $where = array('id' => $id);        $this->m_data->hapus_data($where,'blogs');        redirect('Postingan');    }
查看完整描述

3 回答

?
SMILET

TA貢獻1796條經驗 獲得超4個贊

不要忘記像這樣包含 jQuery Calculate


function hapus($___id) {  

  swal.fire({

        title: 'Are you sure?',

        text: "Are you sure you want to proceed ?",

        type: 'warning',

        showCancelButton: true,

        confirmButtonText: 'Yes'

    }).then(function(result) { 

        if (result.value) {

            $.ajax({

                url : `postingan/hapus/${$___id}`,

                type : 'GET',

                dataType:'json',

                beforeSend: function() {

                    swal.fire({

                        title: 'Please Wait..!',

                        text: 'Is working..',

                        onOpen: function() {

                            swal.showLoading()

                        }

                    })

                },

                success : function(data) { 

                    swal.fire({

                        position: 'top-right',

                        type: 'success',

                        title: 'User  deleted successfully',

                        showConfirmButton: false,

                        timer: 2000

                    });

                 },

                complete: function() {

                    swal.hideLoading();

                },

                error: function(jqXHR, textStatus, errorThrown) {

                    swal.hideLoading();

                    swal.fire("!Opps ", "Something went wrong, try again later", "error");

                }

            });

        }

    });

}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/sweetalert2.all.min.js"></script>


<button onclick="hapus(10)" style="width:70px" type="button" class="btn btn-block btn-outline-danger">Hapus</button>


查看完整回答
反對 回復 2022-07-22
?
藍山帝景

TA貢獻1843條經驗 獲得超7個贊

我想嘗試回答,因為現在我遇到了同樣的問題,用甜蜜警報確認刪除數據。所以我使用帶有ajax(post)的方法并工作。


首先在按鈕中獲取id數據


 <button onclick="hapus(<?php echo $b->id; ?>)" style="width:70px"type="button" class="btn btn-block btn-outline-danger"><?php echo 'Hapus');  ?></button>

然后使函數刪除調用sweetalert


function del(id){

  Swal.fire({

  title: 'Yakin menghapus?',

  text: "Data yang sudhah dihapus tidak dapat dikembalikan!",

  icon: 'warning',

  showCancelButton: true,

  confirmButtonColor: '#3085d6',

  cancelButtonColor: '#d33',

  confirmButtonText: 'Ya, hapus sekarang!'

  }).then((result) => {

    if (result.value) {

      Swal.fire({

        title: 'Terhapus!',

        text: 'Data berhasil dihapus.',

        icon: 'success',

        showConfirmButton: false

      });

      $.ajax({

        type:"POST",

        url: "back/rule/kontak_blog/del", //url function delete in controller

        data:{

          id:id //id get from button delete

        },

        success:function(data){ //when success will reload page after 3 second

         window.setTimeout( function(){ 

             location.reload();

         }, 300 );

        }

      });

    }

  })

}

控制器刪除


function del() {

    $id = $this->input->post('id'); //get data from ajax(post)

    $del = $this->M_kontak_blog->del($id);

}

模型刪除


function del($id) {

    $this->db->where('kb_id', $id);

    $this->db->delete(' tb_kontak_blog');

}

我希望這個答案能幫助你


查看完整回答
反對 回復 2022-07-22
?
元芳怎么了

TA貢獻1798條經驗 獲得超7個贊

嘗試這個


swal.fire({

        title: 'Are you sure?',

        text: "Are you sure you want to proceed ?",

        type: 'warning',

        showCancelButton: true,

        confirmButtonText: 'Yes'


    }).then(function(result) { 

        if (result.value) {

            $.ajax({

                url : 'enter your url',

                type : 'POST',

                data : {id:id },

                dataType:'json',

                beforeSend: function() {

                    swal.fire({

                        title: 'Please Wait..!',

                        text: 'Is working..',

                        onOpen: function() {

                            swal.showLoading()

                        }

                    })

                },

                success : function(data) { 

                    swal.fire({

                        position: 'top-right',

                        type: 'success',

                        title: 'User  deleted successfully',

                        showConfirmButton: false,

                        timer: 2000

                    });

                 },

                complete: function() {

                    swal.hideLoading();

                },

                error: function(jqXHR, textStatus, errorThrown) {

                    swal.hideLoading();

                    swal.fire("!Opps ", "Something went wrong, try again later", "error");

                }

            });

        }

    });

這是控制器


function hapus($id){

        $where = array('id' => $id);

        $this->m_data->hapus_data($where,'blogs');

        //echo true; OR return true;

    }


查看完整回答
反對 回復 2022-07-22
  • 3 回答
  • 0 關注
  • 238 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號