0

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};
      ...
}

1 Answer 1

2

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'])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.