I am having a problem when I send data to Codeigniter via Angular $ post. I am using this JS code:
$scope.user.first_name = 'first name';
$scope.user.last_name = 'last name';
$http({
method: 'POST',
url: '/registration',
data: {user: $.param($scope.user)},
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
}
}).then(function successCallback(response) {
console.log(response)
}, function errorCallback(response) {
console.log(response);
});
My PHP is based on another answer from StackOverflow, but still not working:
echo file_get_contents('php://input');
var_dump($this->input->post());
but this way I see the answer is an empty array if I say:
var_dump($this->input->post('user'));
I see a NULL answer, Same thing with:
var_dump(json_encode($this->input->post()));
with or without a key. Even if I use:
var_dump($_POST);
for the answer, I get an empty array.
How to send and receive data through the $ post Angular service using Codeigniter?
source
share