从angularjs http请求成功(数据)中拆分值

时间:2015-07-11 23:45:18

标签: php angularjs codeigniter ionic hybrid-mobile-app

我正在尝试使用angularjs http i用户codeigniter作为服务器端从php服务器获取数据 这是我的codeigniter控制器

 public function searchuser() {

    $postdata = file_get_contents("php://input");
    $request = json_decode($postdata);
    $this->load->model('user_model');
    $data["users"] = $this->user_model->getuserpro($request->email);

  print_r($data);
}

这是我的codeigniter模型

`function getuserpro($uid) {
        $query = $this->db->get_where("user", array("email" => $uid));
       return $query->result();
    }`

这是我的角度控制器

`angular.module('starter').controller('profileCtrl', function($scope, $state, userlog, $http) {
    var request = $http({
        method: "post",
        url: "http://mydomain/Home/searchuser",
        data: {
            email: userlog.email,
        },
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    });

    /* Check whether the HTTP Request is successful or not. */
    request.success(function(data) {

        document.getElementById("namemy").textContent = data;
        console.log(data);
    });

});

` 当我记录数据时,就像这样

    "Array
(
    [users] => Array
        (
            [0] => stdClass Object
                (
                    [iduser] => 171
                    [email] => chhdshfh@gmail.com
                    [password] => 123
                    [fname] => cha
                    [lname] => shm
                    [dbth] => 1989-08-19 00:00:00
                    [addone] => aaaaaaaa
                    [addtwo] => cccccccccccc
                    [city] => bbbbbbbbbbbbb
                    [country] => LK
                    [tp] => 0111111111
                    [currency] => LKR
                    [gender] => A
                    [job] => sdfsdf
                )

        )

)
"

我如何分割这个数组并将值分配给单独的变量,如id,email,password,fname,lname我试过这样

 ` $scope.id=data.iduser;
        $scope.email=data.email;
        $scope.pass=data.password;
        $scope.fname=data.fname;
        $scope.lname=data.lname;`

这不起作用请任何一个帮助

0 个答案:

没有答案