首页 > 解决方案 > 如何在codeiginter中删除之前使用confirm

问题描述

$(document).ready(function (){
  $('#Delete').on('click', function() {

    var no = $('#bill').val();

    if(confirm('Are you sure to remove this record ?'))
    {
      $.ajax({
        url: "<?php echo base_url();?>TipUp_Loan/Bill_Delete"+no,
        type: 'DELETE',

        error: function() {
          alert('Something is wrong');
        },
        success: function(data) {
          //  $("#"+no).remove();
          alert("Record removed successfully");  
        }
      });
    }
  });
});

这是查看页面代码...

public function Bill_Delete(){
    $session_data = $this->session->userdata('logged_in');
    $data['username'] = $session_data['username'];
    //$Search = $this->input->post('Search1');

    $this->User_model->Bill_Delete($_POST["no"]);
}

这个控制器代码............

public function Bill_Delete($no)
{
    $this->db->where('billno', $no);
    $this->db->delete('salesitem');
    $this->db->where('no', $no);
    $this->db->delete('salesbill');
    echo "Successfully delete";
}

这是型号代码

我的prblm是如何创建确认消息。这只是显示消息,它不会删除到数据库中............

标签: phpcodeigniter

解决方案


您可以通过在按钮标签中添加此 window.confirm 来实现此目的

<button type="submit" class="btn btn-primary" onclick="return confirm('Are you sure want to delete')">Delete<i class="icon-bin position-left"></i></button>

推荐阅读