在我的JQuery DataTable中,“删除”行在客户端运行,但在服务器端使用ajax无法运行

时间:2018-07-07 06:59:20

标签: jquery ajax codeigniter datatables

    var BASE_URL = 'http://172.16.1.105/anusha_qa/index.php/';

    deleteCustomer = function ( customer_id ){


        var table = $('#myDataTable').DataTable();
              var id = $(this).attr('customer_id');

        $( '#myDataTable tbody' ).on( 'click', 'tr', function () {
                    alert("Are you Sure to Delete?");
              if ( $(this).hasClass('selected') ) {
                   $(this).removeClass('selected');
              }

              else {
                   table.$('tr.selected').removeClass('selected');
                   $(this).addClass('selected');
               }
         });

         $.ajax({
                   url: BASE_URL+"CustomerDelete/index",
                   type: "POST",
                   data: {
                        'customer_id':customer_id},
                    success: function(result){  

                      table.row('.selected').remove().draw( false,2000 );
                   }
              });

    }


    Delete controller is 
    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    class CustomerDelete extends CI_Controller{

            function __construct(){
        //constructor       
                parent::__construct();
                $this->load->model('CustomermodelDelete');

            }

       // delete  all tables 

            public function index() {


                $customer_id = $this->input->post('customer_id');

                //$this->customerData($customer_id);
                //$this->addressData($customer_id);
                //$this->carData($customer_id);

                //redirect('customer_list/index');

            }

        //du_customer table

            public function customerData($customer_id){

                $this->CustomermodelDelete->customerTable($customer_id);

            }

        //du_customer_address table

            public function addressData($customer_id){

                $this->CustomermodelDelete->addressTable($customer_id);

            }

        //du_customer_car table

            public function carData($customer_id){

                $this->CustomermodelDelete->carTable($customer_id);


            }

    }



    and This my model page to delete the data,

    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');

    class CustomermodelDelete extends CI_Model{

        function __construct(){
                parent::__construct();
            }


        //delete from du_customer       

        public function customerTable($customer_id){

                    $this->db->where('customer_id', $customer_id);
                    $this->db->delete('du_customer');
            }
    //delete from du_customer_address

            public function addressTable($customer_id){

                    $this->db->where('customer_id', $customer_id);
                    $this->db->delete('du_customer_address');
            }
    //delete from du_customer_car

            public function carTable($customer_id){

                    $this->db->where('customer_id', $customer_id);
                    $this->db->delete('du_customer_car');
            }
        }

    ?>

我要删除选定的表行。删除工作在客户端,但我想从数据库中删除。数据表ID为myDataTable。我在j查询数据表中是新的。我正在使用Code-igniter 3,MVC模式,我不知道实际的问题是什么。请某些机构帮助我 任何帮助都非常可观。谢谢

1 个答案:

答案 0 :(得分:0)

查看您的Ajax脚本。您指的是 url ,如下所示 URL:BASE_URL +“ CustomerDelete / index”,

尝试这个。

public function index() {
        // Let's give your model an alias
        $this->load->model('CustomermodelDelete', 'deleterecord');

        $customer_id = $this->input->post('customer_id');

        // This should do the trick
        $this->deleterecord->customerTable($customer_id);               
}