douwen1313 2017-01-12 13:42
浏览 25
已采纳

离子角度 - 注册问题

Controller for sign-up

.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
                });


            });

    }
})

Backend signup.php few lines

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
} }

As per debugging there is no issue i found in angular as well as php code, when debugging i found in php $_GET['n'] is not working so the rest of get codes.

Sort this out.

  • 写回答

1条回答 默认 最新

  • drqyxkzbs21968684 2017-01-12 13:47
    关注

    Why you're using $_GET in php. You should use $_POST in php since in angular you're using $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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?