I've added a constructor in a class to check if some user is logged in.
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->library('encryption');
if (!$this->session->userdata('id') || $this->session->userdata('role') != 'CUSTOMER') {
redirect('account/login');
}
}
Here's the ajax
$.ajax({
type:'POST',
url:'<?php echo base_url("cart/addToCart"); ?>',
dataType: 'text',
data:{'id':val},
success:function(data) {
if (data != 'added') {
alert('Opps! something went wrong, please try again');
}
}
});
but if I try to call this request without session, it's not redirecting to login page but giving the whole login page code which I can see in network tab