Angularjs $httppost data to PHP receive questions ANGULARJS 2.0 Angularjs video tutorial angularjs directive

Source: Internet
Author: User
Recently learned Angularjs, found using its own $http.post back to PHP to send data, PHP received the problem. Like what:

$http. Post ("php/getroleright.php", {rr: $scope. Currselect}). Success (function (response) {·});
PHP usage
$_post[' RR ']
Cannot receive the passed-over parameters.

Open Firebug found actually success, tossing the long time only found that it is only the format of transmission and ordinary transmission format such as the $.post () method in jquery, the format of the transmission, $http. Post () is transmitted in JSON format, and $.post () is transmitted as a form parameter, while PHP $. Post[] is expected to receive the data transmitted from the foreground in the form of the latter, so it cannot read JSON data.

Surfing the internet and adding your own experiments, there are two ways to solve this problem:

1. Simple and rude directly to the $.post () method, so that the background does not make any changes, but online some more experienced netizens said this may violate the original intention of using angular.

2. Modify the PHP code

$postData = file_get_contents (' Php://input ', true); $obj =json_decode ($postData); $query 1 = "SELECT * FROM Role_roleright  WHERE roleid= $obj->rr ";
The JSON string is read first and parsed into an object so that the value of the parameter RR passed in is taken from the object's properties.

All right, it's done.

The above describes the Angularjs in the $httppost data to the PHP receive problems, including the angularjs aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.