I have the following Ajax request
var csrfName = '<?php echo $this->security->get_csrf_token_name();?>';
var csrfHash = '<?php echo $this->security->get_csrf_hash();?>';
var searchTerm = $("#mastheadSearch").val();
var data = {};
data['Search'] = searchTerm;
data[csrfName] = csrfHash;
$.ajax({
type: 'POST',
url:'<?=base_url()?>news/support',
contentType : 'application/json',
data:JSON.stringify(data),
});
But I can not access this information from the controller.
$rawData = file_get_contents("php://input");
$newData = json_decode($rawData);
The strange thing is that if I insert a breakpoint with xdebug, it says the variable $newData has a value (which is the value I expected it to be). However if I try and access this variable within my code I get an error message (Severity: Notice
Message: Trying to access array offset on value of type null).
I have read posts of people with similar issues and tried the suggested fixes but none seem to work for me.