Retrieve angular value POST

0

How do I retrieve the value in the php file when I use this angularjs post method?

 $http({
                    method  : 'POST',
                    url     : 'xxxxxxx.com/consulta.php',
                    data    : JSON.stringify($scope.newName),
                    headers : { 'Content-Type': 'application/x-www-form-urlencoded' } 
                    }) .success(function (data) {
                $scope.nomes = data;            
            });  

I send the parameters by date: JSON.stringify ($ scope.newName)

In the php file how do I retrieve this value?

    
asked by anonymous 17.02.2016 / 03:08

1 answer

1

The passing of the date parameter has to be done as a pair of attributes as the following example:

...
data : {c: JSON.stringify(nomeObj)},
...

In the PHP part:

$data = file_get_contents("php://input");
$data = json_decode($data);
$c = json_decode($data->c); //o ->c tem de ter a mesma designação que é passado 

I hope it helps.

    
17.02.2016 / 10:32