从JQuery调用CodeIgniter方法

I want to call codeigniter method using jquery. My ajax call is working but getting an error. I have added my controller, model, ajax call and error.

According to:

$("body").on("click", ".call-ajax", function() {
    // obtém o valor do link
    console.log("chamada ajax");

    var caminho = "http://localhost/xxxxx/public/uploads/anexos/";


    data = {
      id_rec: $(this).data("id_rec"),
      anexo: caminho + $(this).data("anexo")
    };

    console.log(data);

    // AJAX para o controller
    $.ajax({
      url: "reclamacao/delete_anexo",
      data: data,
      type: "POST"
    }).done(function(resp) {
        console.log("deleção OK");
      // Display the resposne
      //$("#result").append($("<li/>").html(resp));
    });
  });

It correctly calls

Check Image 1

But this error occurs:

Check image 2

My CONTROLLER CODE:

public function delete_anexo($id, $file)
{
    try
    {
        if (!$this->input->is_ajax_request())
        {
            $this->output->set_status_header(404);
            return;
        }
        if (!$this->anexo_model_reclamacao->delete_anexo($id, $file))
            throw new Exception("Erro ao excluir", 1);

        $alert = 'Operação Realizada com sucesso.';
    }
    catch (exception $e)
    {
        $alert = $e->getMessage();
    }

    bootbox_alert($alert);
}

MODEL CODE:

 public function delete_anexo($id, $file) {
        $this->db->delete($this->table, array('id_reclamacao' => $id, 'file' => $file));
        return true;
    }

This declaration in the controller public function delete_anexo($id, $file) assumes that the $id and $file are in the url e.g. reclamacao/delete_anexo/{$id}/{$file} which is clearly not what you want by your data jquery declaration. Thus you need to capture the post vars like so:

public function delete_anexo()
{
    try
    {
        if (!$this->input->is_ajax_request()) {
            $this->output->set_status_header(404);
            exit;
        }
        $id = $this->input->post('id_rec');
        $file = $this->input->post('anexo');
        if (is_null($id) || is_null($file)) {
            throw new Exception('Parameters missing');
        }
        if (!$this->anexo_model_reclamacao->delete_anexo($id, $file)) {
            throw new Exception("Erro ao excluir", 1);
        }
        $alert = 'Operação Realizada com sucesso.';
    }
    catch (exception $e)
    {
        $alert = $e->getMessage();
    }

    bootbox_alert($alert);
}

The second error image that you have posted is clearly stating that the second argument is missing from your method call, please double check whether both the arguments are getting posted when you are making the ajax call.