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
But this error occurs:
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;
}