获取使用AngularJs传递给php的参数

时间:2016-06-20 17:38:44

标签: php angularjs

我有一个简单的editCategory()函数,传递id作为参数,但我不知道在PHP代码中获取id的正确方法是什么并将其设置为变量

$scope.EditCategory = function(id) {
        $http.get('details.php', {'id': id})
        .success(function(data, status, headers, config) {
            ngDialog.open({
                template: "details.html"
            });
        }).error(function(data, status) {
            $scope.msg = 'Some error';
            $scope.msg_type = 'error';
        });
    };

在php中我希望$id = the id that I passed with Angular

3 个答案:

答案 0 :(得分:0)

您正在使用$http.get,因此值将在GET中。

$id = $_GET["id"];

答案 1 :(得分:0)

答案是json_decode(file_get_contents('php://input'), true)["id"]

答案 2 :(得分:0)

$ HTTP.get / post并没有真正成为真正的$ _post。你想要的是使用:

json_decode(file_get_contents('php://input'), true)["id"]