Codeigniter csrf token with ajax request (500 internal server error) Codeigniter csrf token with ajax request (500 internal server error) codeigniter codeigniter

Codeigniter csrf token with ajax request (500 internal server error)


Add the CSRF token to your data option before posting:

 $.ajax({    type: "POST",    url: $this.attr("action"),    data: {'<?php echo $this->security->get_csrf_token_name(); ?>':'<?php echo $this->security->get_csrf_hash(); ?>',/*....your data....*/},    beforeSend: function() {        mensaje.html('<p><img src="public/frontend/img/miniloader.gif"><span><small> Iniciando..</small></span></p>');    }})

The CSRF token needs to be sent with each request so it should be specified by the data. The echo statement does this. You can add this separately and serialize, but I've shown what you are missing.