Recover value Angularjs POST

Asked

Viewed 332 times

0

How to recover the value in 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 php file how to recover this value?

1 answer

1


The passage 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.

  • It worked, thanks, and how do I pass 2 parameters?

  • @Yurirodrigues Passes an array with the 2 parameters :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.