使用AJAX删除CodeIgniter时出现问题

时间:2019-02-17 19:31:05

标签: javascript php jquery ajax codeigniter

我想删除表格工具中的寄存器,我在AJAX中使用codeignite,并且在控制器中具有此功能

public function deleteInstrument(){
    $id = $this->input->get('id');
    $sql = $this->db->where('id',$id)->delete('instrumentos');
    $r['response'] = 2;
    $r['content'] = 'deleted';
    echo json_encode($r);
}

我的JavaScript中有一个要删除的下一个函数:

function confirmarEliminar(){
    $("body").on("click","#tablaInstrumentos button",function(event){
        idseleccion=$(this).attr("value");
        alertify.confirm('Eliminar Registro',
                 'Esta seguro de eliminar el registro?',
                  function(idseleccion){
                    $.ajax({
                        url: base_url+'admin_ajax/deleteInstrument',
                        type: 'GET',
                        data:{id:idseleccion},
                        beforeSend:function(){
                        },
                        success:function(r){
                           if(r==2 ){
                               alert(id)

                           }
                        },
                        error:function(xhr, status, msg){
                            console.log(xhr.responseText);
                        }
                    });
                   }

            , function(){ alertify.error(idseleccion)});

    });}

我在控制台输出中出现此错误

Uncaught TypeError: Illegal invocation
at i (jquery-3.3.1.min.js:2)
at jt (jquery-3.3.1.min.js:2)
at jt (jquery-3.3.1.min.js:2)
at jt (jquery-3.3.1.min.js:2)
at jt (jquery-3.3.1.min.js:2)
at jt (jquery-3.3.1.min.js:2)
at Function.w.param (jquery-3.3.1.min.js:2)
at Function.ajax (jquery-3.3.1.min.js:2)
at Object.<anonymous> (configuracion.js?1550431424:80)
at Object.callback (alertify.min.js:3)

1 个答案:

答案 0 :(得分:0)

请在js中尝试以下代码: 函数confirmarEliminar(id){

            $.post(base_url + "admin_ajax/deleteInstrument", {id: id}, function (data) {
                if (data.code == '1') {
                    bootbox.alert(data.message, function () {
                        $("#your row id" + id).remove();


                    });
                } else {
                    bootbox.alert('Something went wrong');
                }
                $(window).unblock();
            });

}

控制器代码:

公共函数deleteInstrument($ id){ }

相关问题