Reputation: 135
What is the easiest whay to send js array from angular controler to my Codeigniter controler.I want this to print this
Array ( [kalorije] => 0 [proteini] => 0 [uh] => 0 [masti] => 0 )
.
Please test it before ansering and tell me if i need to set up some configuration before doing it becouse i tried everything and nothing works.
Codeigniter
public function catchData(){
$CIarray = ...
print_r($CIarray);
}
Angular
$scope.sendToControler = function () {
$scope.prosek = {kalorije: 0.0, proteini: 0.0, uh: 0.0, masti: 0.0};
...
}
Upvotes: 0
Views: 48
Reputation: 4019
Here's what's worked for me: On the angular side:
return $http({method: "POST",
dataType: "json",
url:'/myURL/',
data: $.param({data: JSON.stringify(data)}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
.success(function(data) {
//Handle Success;
});
On the PHP side
$CIarray = json_decode($_POST['data'])
Upvotes: 2