Home >Backend Development >PHP Tutorial >$httppost in angularJS transmits data to php to receive problems angularjs 2.0 angularjs video tutorial angularjs directive
I recently learned angularJS and found the problem that using its own $http.post to send data to the background php, php cannot receive it. For example:
$http.post("php/getRoleRight.php", {rr:$scope.currSelect}).success(function(response) { ·· });PHP cannot receive the passed parameters when using
$_POST['rr'].
After looking online and doing my own experiments, there are two ways to solve this problem:
1. Simply and crudely change it directly to the $.post() method, so that no modification is used in the background, but some online More experienced netizens said that this may defeat the original intention of using angular.
2. Modify the php code
$postData = file_get_contents('php://input', true); $obj=json_decode($postData); $query1 = "SELECT * FROM role_roleRight WHERE roleId=$obj->rr";first reads the json string and then parses it into an object. In this way, the value of the passed parameter rr can be obtained using the object attribute.
Okay, you’re done.
The above introduces the problem of $httppost in angularJS transmitting data to php for receiving, including the content of angularjs. I hope it will be helpful to friends who are interested in PHP tutorials.