windows 10, codeigniter 3, jquery 3
I am testing the ajax function and I am loading data into a div by using the $.post function and sending to a controller method that reads a file and sends back the contents (I know there are other ways of doing it but this is a test). The ajax call looks like this
var btn = 'a[href="click-help"]'
$(btn).click(function(){
$.post(
base_url+'site/cal_help',
function(data){
$('.cal-help').html(data);
});
}
return false;
});
You can see that the click button is not a form but a link. This works OK when I have csrf set to false but the console shows the call as forbidden if csrf is enabled. Having researched online, I have tried passing data as follows:
{
'<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>'
},
but it doesn't help. How can I fix it without setting csrf to false, which I would rather not do in case I want it for other elements in the site?