离子角度 - 注册问题

时间:2017-01-12 13:42:12

标签: php angularjs

注册控制器

.controller('signupCtrl', 

function($scope,$http,$ionicPopup,$state,$ionicHistory) {

    $scope.signup=function(data){
            var link = 'http://localhost/b_data/server/signup.php';
            $http.post(link, {n : data.name, un : data.username, ps : data.password , ph: data.phone , add : data.address , pin : data.pincode })
            .then(function (res){   
                $scope.response = res.data.result; 
                if($scope.response.created=="1"){   
                    $scope.title="Account Created!";
                    $scope.template="Your account has been successfully created!";

                    //no back option
                    $ionicHistory.nextViewOptions({
                        disableAnimate: true,
                        disableBack: true
                    });
                    $state.go('login', {}, {location: "replace", reload: true});

                }else if($scope.response.exists=="1"){
                    $scope.title="Email Already exists";
                    $scope.template="Please click forgot password if necessary";

                }else{
                    $scope.title="Failed";
                    $scope.template="Contact Our Technical Team";
                }

                var alertPopup = $ionicPopup.alert({
                        title: $scope.title,
                        template: $scope.template
                });


            });

    }
})

后端signup.php几行

if(isset($_GET["n"]) && isset($_GET["un"])&& isset($_GET["ps"])&& isset($_GET["ph"])&& isset($_GET["add"])&& isset($_GET["pin"]) )  {
    if( !empty($_GET["n"])  && !empty($_GET["un"])&& !empty($_GET["ps"])&& !empty($_GET["ph"])&& !empty($_GET["add"])&& !empty($_GET["pin"])  ){
 //rest of my db saving code
} }

根据调试,我发现在角度和PHP代码中都没有问题,当我在php中发现调试 $ _ GET ['n'] 时没有工作,所以其余的get代码。

将其排除。

1 个答案:

答案 0 :(得分:1)

为什么你在php中使用$ _GET。你应该在php中使用$ _POST,因为在角度你使用$ http.post。

<强> JS

var json = {n : data.name, un : data.username, ps : data.password , 
           ph: data.phone , add : data.address , pin : data.pincode };

// Update wrap object with curly bracket
$http.post(link, {data: json}).then(...);

<强> PHP

// Added json decode
$data = file_get_contents("php://input");
$postData = json_decode($data);

$n = $postData->n;