0

I am using ajax to fetch the data from database. There are about 20 records in database. Here is the php code to fetch the data.

$query = "SELECT user_id,website,emailid FROM job_posting where uid = ? order by date DESC";

        $result = $mysqli->prepare($query);
        $result ->bind_param("i",$uid);
        $result->execute();
        $result->store_result();

        $result->bind_result($user_id,$website,$emailid);
        if($result->num_rows >0){

                while ($result->fetch()) {

                    $website = $website;
                    $emailid = $emailid;
                    $user_id = $user_id;

                    $data['content'][] = array(

                    'website' => $website,
                    'emailid' => $emailid,
                     'user_id' => $user_id,  
                    );



                }
             $data['success'] = 'true'; 
     }
     echo json_encode($data);
}

Above code is working fine. I can see the data in json format. Sample below.

{"content":[{"website":"test.com","emailid":"[email protected]","user_id":1},{"website":"test.com","emailid":"[email protected]","user_id":2},{"website":"test.com","emailid":"[email protected]","user_id":3}],"success":"true"}  

Now I want to show this data by angular in webpage.

Angular code:

     $http({
                        url: 'get_details.php',
                       method: "GET",
                        params: {uid: uid}
                    })
                        .success(function(data) {

                            if (data.success) {

}

Please advise how to show the array data in a div.

<div class="col-md-12>
Need to show website, email id and user id in this div.
</div>

2 Answers 2

1

You should use then instead success . success and error have been deprecated and will be removed in v1.6.0.

 $http({
                        url: 'get_details.php',
                       method: "GET",
                        params: {uid: uid}
                    })
                        .then(function(data) {
                   $scope.data = data.data.content

}

and in div

<div class="col-md-12 ng-repeat="x in data >
{{x.emailid}} - {{x.userid}}
</div>
Sign up to request clarification or add additional context in comments.

Comments

1

It should be like this.(but its better use then function instead of success)

$http({
          url: 'get_details.php',
          method: "GET",
          params: {uid: uid}
       })
       .success(function(data) {
          $scopemyData = data.content;
        }

and in view

   <div ng-repeat="data in myData">
     <span>{{data.website}}</span>
     <span>{{data.emailid}}</span>
     <span>{{data.user_id}}</span>
   </div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.