0

I want to delete a register in a table instrumentos, I'm using codeignite with AJAX and I have this function in my controller

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);
}

And I have in my JavaScript the next function to delete:

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)});

    });}

I have this error in the console output

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)
Zoe
  • 27,060
  • 21
  • 118
  • 148
Anderson Laverde
  • 316
  • 1
  • 4
  • 15
  • without seeing your mark-up I can only guess: `idseleccion=$(this).attr("value");` should be `idseleccion=$(this).val();` see here: https://stackoverflow.com/questions/8312820/jquery-val-vs-attrvalue AND the variable base_url? is it defined? I can't see how? – Vickel Feb 17 '19 at 19:44
  • I Solve my problem with your help, really thanks my friend, you are the best – Anderson Laverde Feb 17 '19 at 21:22
  • I'm happy that my comment helped you. Anyway, to make your question useful for other people, please consider to update your question to be more on focus and also to provide an answer, how you managed to solve it, thanks. https://stackoverflow.com/help/self-answer – Vickel Feb 17 '19 at 22:59

1 Answers1

0

Please try this code in js: function 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();
            });

}

Controller Code:

public function deleteInstrument($id){ }

PHP Geek
  • 3,949
  • 1
  • 16
  • 32